From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE6B3C433ED for ; Mon, 12 Apr 2021 13:05:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABC2861003 for ; Mon, 12 Apr 2021 13:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241660AbhDLNGG (ORCPT ); Mon, 12 Apr 2021 09:06:06 -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