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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1367CCDB47E for ; Fri, 20 Oct 2023 09:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376808AbjJTJWW (ORCPT ); Fri, 20 Oct 2023 05:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376678AbjJTJV6 (ORCPT ); Fri, 20 Oct 2023 05:21:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E8F71728 for ; Fri, 20 Oct 2023 02:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697793679; x=1729329679; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=a++LVpgYV0t0DpSZeHCFw0R4XO+/PCphuhcdSRisZ/4=; b=nCLyKBFKlPQhiWGIUpI0FoBljO9qjq6VEjzfQsU9ygEW4A36QyuI1Qh9 TKobgB1g8xd2vGoQcffqZw/TPapxS2ny+fiZt9Q2L5iWQFypCKfXATvv1 jjMdylG8qywOLlXgn3EDHYEf9t59rN8JPplIylKbl2hYw7G6bcyUmVYjV 4qBeRwz/TH34A5Eo1ZDKQ8BuVZpY8WFfxVqC4WQE/BZUPnaUwQ2pKE2B7 j44cU0LzSQoIPt4CCg1oz15TMPRkYHYevNnHvFW9FX/lQc/pJDoi43fdW mfeVbGc0Kg3g1K8O/CjOj3TpLEjn+EAXEv9HEkFpf2Wao9ikIcsQQlEgg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="365802084" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="365802084" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 02:21:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="760990089" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="760990089" Received: from blavena-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.39.237]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 02:21:13 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 2344E109D0A; Fri, 20 Oct 2023 12:21:11 +0300 (+03) Date: Fri, 20 Oct 2023 12:21:11 +0300 From: "Kirill A. Shutemov" To: "Kalra, Ashish" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/13] x86/tdx: Convert shared memory back to private on kexec Message-ID: <20231020092111.ho2rmhve23kgcxbr@box> References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> <20231005131402.14611-11-kirill.shutemov@linux.intel.com> <8d0e4e71-0614-618a-0f84-55eeb6d27a6d@amd.com> <20231005212828.veeekxqc7rwvrbig@box> <20231005222839.jt2du72xogg3c5ny@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 06, 2023 at 02:24:11PM -0500, Kalra, Ashish wrote: > > On 10/5/2023 5:28 PM, Kirill A. Shutemov wrote: > > On Thu, Oct 05, 2023 at 05:01:23PM -0500, Kalra, Ashish wrote: > > > On 10/5/2023 4:28 PM, Kirill A. Shutemov wrote: > > > > On Thu, Oct 05, 2023 at 01:41:38PM -0500, Kalra, Ashish wrote: > > > > > > +static void unshare_all_memory(bool unmap) > > > > > > +{ > > > > > > + unsigned long addr, end; > > > > > > + long found = 0, shared; > > > > > > + > > > > > > + /* > > > > > > + * Walk direct mapping and convert all shared memory back to private, > > > > > > + */ > > > > > > + > > > > > > + addr = PAGE_OFFSET; > > > > > > + end = PAGE_OFFSET + get_max_mapped(); > > > > > > + > > > > > > + while (addr < end) { > > > > > > + unsigned long size; > > > > > > + unsigned int level; > > > > > > + pte_t *pte; > > > > > > + > > > > > > + pte = lookup_address(addr, &level); > > > > > > > > > > IIRC, you were earlier walking the direct mapping using > > > > > walk_page_range_novma(), any particular reason to use lookup_address() > > > > > instead ? > > > > > > > > walk_page_range_novma() wants mmap lock to be taken, but it is tricky as > > > > we run here from atomic context in case of crash. > > > > > > > > I considered using trylock to bypass the limitation, but it is a hack. > > > > > > > > > > > > > > > + size = page_level_size(level); > > > > > > + > > > > > > + if (pte && pte_decrypted(*pte)) { > > > > > > > > > > Additionally need to add check for pte_none() here to handle physical memory > > > > > holes in direct mapping. > > > > > > > > lookup_address() returns NULL for none entries. > > > > > > > > > > Looking at lookup_address_in_pgd(), at pte level it is simply returning > > > pte_offset_kernel() and there does not seem to be a check for returning NULL > > > if pte_none() ? > > > > Hm. You are right. > > > > I think it yet another quirk in how lookup_address() implemented. We need > > to make it straight too. > > > > There's two options: either make lookup_address() return pointer for entry > > even if it is NULL, or add check for pte_none() after pte_offset_kernel() > > and return NULL if it is true. > > > > I like the first option more as it allows caller to populate the entry if > > it wants. > > Yes, i like the first option. I tried to this, but lookup_address() has to many callers. It gets beyond the scope of the patchset. I will add pte_none() check on unshare side for now. -- Kiryl Shutsemau / Kirill A. Shutemov