Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2250610pxb; Mon, 12 Apr 2021 19:32:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4VMgrqgZuZ5/PO98AX/byBfxIOZfW9JRO4o+ZelBxo7KwYq53eLRjQCmIEvAbuN0xEYyX X-Received: by 2002:a05:6a00:a86:b029:203:6bc9:3f14 with SMTP id b6-20020a056a000a86b02902036bc93f14mr28235240pfl.22.1618281124301; Mon, 12 Apr 2021 19:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618281124; cv=none; d=google.com; s=arc-20160816; b=nJP88z8Eo/Dl0+zrGiOt8GS5+pUoT3O3oWTu4nRbl03lTptcZzRgksLU5tB6+/YRis vPAOf/Lv9bR0MW2RkIq9CMWEgIQ1RhdUEFLGN8rLBxLUyIQuRbqontTd7nKwBwEhByJg pjo2OXYFUIG0ewPj02116vmR5+irgIugL8bJ6n4hroBo+t60iNMrSgsmeZE1pRZWF0lT FmeLuGW8Uh72T3hw3z3ACs8V5P7k8tTNmANfcKq3QVzfHcb4sGUb8HwSNCKjAPG2dE3M ydpIyaizEpsyRLZ0xwAw1w3en/jvyOgAMf9kKlc4GGOe5qn+4A6XWWat+uj2n6tg7vOd jJIA== 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=t5OPFg3BlJZVYDrFe4E03BZrpdCr/WXWjwTH1yDJrU8=; b=ePpQHymg4ORf3P9k+ZNhq91kRPvgmR32u89I6LYKGmuM/hvgbXjBwawW22Xvu4oSEI aZxNBBNVMst+Pai5NRxwwtRq2QVH5Pb+Dbj4I/GmpmjBEkkYsOMmBDUoytMhV6h9teMf YOCklrRdu8LsHiEy1DmgvFdqvLRFqrWsjjJNOaUN1B8WbMVWkEj06sQm/MQ7U83GS30z coyH4odQ+YsHUWbWt+XcjZRGYHubKfXsvNiggidl5lyQQVbobdyR3Lk1KhrqwAg0FSfP IjFtH4AolU2/wZYGxZJl463GsimrejBqKOFKumVAVKsNOsxXaxRuBFLorcGY3HX86o9u azSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=DByvbxIo; 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 36si9410229pgp.31.2021.04.12.19.31.52; Mon, 12 Apr 2021 19:32:04 -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=DByvbxIo; 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 S241646AbhDLNGF (ORCPT + 99 others); Mon, 12 Apr 2021 09:06:05 -0400 Received: from mail.skyhub.de ([5.9.137.197]:32972 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241655AbhDLNGD (ORCPT ); Mon, 12 Apr 2021 09:06:03 -0400 Received: from zn.tnic (p200300ec2f052100338fe73c52330fca.dip0.t-ipconnect.de [IPv6:2003:ec:2f05:2100:338f:e73c:5233:fca]) (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 98C921EC03A0; Mon, 12 Apr 2021 15:05:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1618232743; 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=t5OPFg3BlJZVYDrFe4E03BZrpdCr/WXWjwTH1yDJrU8=; b=DByvbxIo8cF2XQWnCk3SvDu9G+PWCG9n5Hepw/e66gd7Cq4DPBsaCMw9spqnMEQf7wZfqe 949QomuG/TukIlvPPqeEe6m/WskcbXd1lIBtSd1JD0B1GncZxzXZDM6IekTMuYZbCOaot+ +YpjWsvKUF7mE7ttofdPQERqG+xUDYw= Date: Mon, 12 Apr 2021 15:05:42 +0200 From: Borislav Petkov To: Brijesh Singh Cc: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, ak@linux.intel.com, Thomas Gleixner , Ingo Molnar , Joerg Roedel , "H. Peter Anvin" , Tony Luck , Dave Hansen , "Peter Zijlstra (Intel)" , Paolo Bonzini , Tom Lendacky , David Rientjes , Sean Christopherson Subject: Re: [RFC Part1 PATCH 13/13] x86/kernel: add support to validate memory when changing C-bit Message-ID: <20210412130542.GD24283@zn.tnic> References: <20210324164424.28124-1-brijesh.singh@amd.com> <20210324164424.28124-14-brijesh.singh@amd.com> <20210412114901.GB24283@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 12, 2021 at 07:55:01AM -0500, Brijesh Singh wrote: > The cur_entry is updated by the hypervisor. While building the psc > buffer the guest sets the cur_entry=0 and the end_entry point to the > last valid entry. The cur_entry is incremented by the hypervisor after > it successfully processes one 4K page. As per the spec, the hypervisor > could get interrupted in middle of the page state change and cur_entry > allows the guest to resume the page state change from the point where it > was interrupted. This is non-obvious and belongs in a comment above it. Otherwise it looks weird. > Since we can get interrupted while executing the PSC so just to be safe > I re-initialized the scratch scratch area with our buffer instead of > relying on old values. Ditto. > As per the spec the caller must check that the cur_entry > end_entry to > determine whether all the entries are processed. If not then retry the > state change. The hypervisor will skip the previously processed entries. > The snp_page_state_vmgexit() is implemented to return only after all the > entries are changed. Ditto. This whole mechanism of what the guest does and what the HV does, needs to be explained in a bigger comment somewhere around there so that it is clear what's going on. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette