Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp329676pxb; Wed, 25 Aug 2021 04:28:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKGKMA/iAffCIzYVic7o7XBbSpGHdJThRDVdZML5mPsdLsFgp0P4St01eHqeThrM82+lEZ X-Received: by 2002:a6b:8b54:: with SMTP id n81mr34375288iod.5.1629890929888; Wed, 25 Aug 2021 04:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629890929; cv=none; d=google.com; s=arc-20160816; b=OfcbcbO6hYhIDa64G2ZlY1mdUoSqpPBNhnRSK6euVRqvNJZayOtRSX9UMJVtMIHIF/ fXQLMO5CuFI7lAWJMFA88gJqBqUQ153IlkbluBVbelH5R8nMpwDClebFSDsAyUCxDLhG 3XJKrmdlQAx7UkdxzNqBPTE8fv3sX6W+pbom+kD6MWDaceRboquXue5343Tko2YYkpdY YaNcPHQNL3HJgnkZbLAJDm8EcpsA1QQfuiPg9tyShbwXMKFYJVlsH6KhUvDV6YzjDj48 tXYycCvB+R+AQ5dVpnlHLEe4RveY1jxT2D+8YoC8yxK1amEtOQT24hNKPf4pEtvHAlXA 3E/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FmlAznHkQY06DZXhalxR6XDiPNF7pgBGfOoUZA3D+vo=; b=017Ot/o5cJSGrj0QcdFQ/koKASvvTx7rDCaknUg856hrzc5QvDF/mCVf2x46kPG0Y7 7PCqtUq6xdshQv3NvV7EvT3uvEraVylkvjG8x2PtVSfRFF4KU/81oVeyiEREsOVGEZvK pMLZdpbnsdKfbtu2wBp+bQkAmztU6qorsC0WGj8GqTnLf3DWzKoKGYj0GE4UVrVZwbZn OMqsmAnUtIKboMq3YJJp0YMtuJ01L/JjeqW6lMEP1jgnfgWhGKUJZKcLeF0aHt1cdy9b d1l7TaoGAzpD/MPVq05UOTXahkbp4eMhzp2wr8Zmo7FNcqyaaiOWZSPAFyduffCKS54C Yuxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=jy+S22x5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si21970763jao.99.2021.08.25.04.28.39; Wed, 25 Aug 2021 04:28:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=jy+S22x5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239968AbhHYLGV (ORCPT + 99 others); Wed, 25 Aug 2021 07:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236038AbhHYLGU (ORCPT ); Wed, 25 Aug 2021 07:06:20 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9086C061757; Wed, 25 Aug 2021 04:05:34 -0700 (PDT) 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210820151933.22401-18-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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