From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.skyhub.de (unknown [5.9.137.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9182C3FC0 for ; Wed, 25 Aug 2021 11:05:47 +0000 (UTC) Received: from zn.tnic (p200300ec2f0ea70083109ebf80d1db9a.dip0.t-ipconnect.de [IPv6:2003:ec:2f0e:a700:8310:9ebf:80d1:db9a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 301C91EC036B; Wed, 25 Aug 2021 13:05:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1629889529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=FmlAznHkQY06DZXhalxR6XDiPNF7pgBGfOoUZA3D+vo=; b=jy+S22x5BGqIj6wZ/EDYcRcJ7KPx0io4/u4mhOd7rT/8pZqVzhf5Cv5q8b5BXMaTO9Timc ZVVHryDmAoSKY5ydD29ngcwnWz0d+uh9eroCZsSt0bdmcrorGFplMCnF55w0a8eFPJAonF XDRO2IL3+/d30AH0qTY8rSaSuGIxBaU= Date: Wed, 25 Aug 2021 13:06:06 +0200 From: Borislav Petkov To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH Part1 v5 17/38] x86/mm: Add support to validate memory when changing C-bit Message-ID: References: <20210820151933.22401-1-brijesh.singh@amd.com> <20210820151933.22401-18-brijesh.singh@amd.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210820151933.22401-18-brijesh.singh@amd.com> On Fri, Aug 20, 2021 at 10:19:12AM -0500, Brijesh Singh wrote: > + while (hdr->cur_entry <= hdr->end_entry) { > + ghcb_set_sw_scratch(ghcb, (u64)__pa(data)); > + > + ret = sev_es_ghcb_hv_call(ghcb, NULL, SVM_VMGEXIT_PSC, 0, 0); > + > + /* > + * Page State Change VMGEXIT can pass error code through > + * exit_info_2. > + */ > + if (WARN(ret || ghcb->save.sw_exit_info_2, > + "SEV-SNP: PSC failed ret=%d exit_info_2=%llx\n", > + ret, ghcb->save.sw_exit_info_2)) { > + ret = 1; > + goto out; > + } > + > + /* > + * Sanity check that entry processing is not going backward. > + * This will happen only if hypervisor is tricking us. > + */ > + if (WARN(hdr->end_entry > end_entry || cur_entry > hdr->cur_entry, > + "SEV-SNP: PSC processing going backward, end_entry %d (got %d) cur_entry %d (got %d)\n", I really meant putting the beginning of that string at the very first position on the line: if (WARN(hdr->end_entry > end_entry || cur_entry > hdr->cur_entry, "SEV-SNP: PSC processing going backward, end_entry %d (got %d) cur_entry %d (got %d)\n", end_entry, hdr->end_entry, cur_entry, hdr->cur_entry)) { Exactly like this! ... > +static void set_page_state(unsigned long vaddr, unsigned int npages, int op) > +{ > + unsigned long vaddr_end, next_vaddr; > + struct snp_psc_desc *desc; > + > + vaddr = vaddr & PAGE_MASK; > + vaddr_end = vaddr + (npages << PAGE_SHIFT); > + > + desc = kmalloc(sizeof(*desc), GFP_KERNEL_ACCOUNT); And again, from previous review: kzalloc() so that you don't have to memset() later in __set_page_state(). > + if (!desc) > + panic("SEV-SNP: failed to alloc memory for PSC descriptor\n"); "allocate" fits just fine too. > + > + while (vaddr < vaddr_end) { > + /* > + * Calculate the last vaddr that can be fit in one > + * struct snp_psc_desc. > + */ > + next_vaddr = min_t(unsigned long, vaddr_end, > + (VMGEXIT_PSC_MAX_ENTRY * PAGE_SIZE) + vaddr); > + > + __set_page_state(desc, vaddr, next_vaddr, op); > + > + vaddr = next_vaddr; > + } > + > + kfree(desc); > +} -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette