Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2663rdb; Thu, 5 Oct 2023 14:28:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG54FcDhxdM1z7lvRWkNOsog8C2qRcSDDcRihOjnwcIALnLc5Jc9H/jmlwWkqN7anDRvqum X-Received: by 2002:a17:90b:3810:b0:26f:ac36:623a with SMTP id mq16-20020a17090b381000b0026fac36623amr3701724pjb.3.1696541329748; Thu, 05 Oct 2023 14:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696541329; cv=none; d=google.com; s=arc-20160816; b=ctfTkue8khn2EqnDk5SJM0AJob/dCqqHhGe/RhHDIv2Fdz2559YulnGcgDYSpoiT/e QmpOB707O0TIEgZSuV6UlJ+HiU0fz7aLyzsE8dE0HmDRYagI+IIZaXgUubgVtsUezjXw vIE8fRkerXjoyuHLHmA9Swr1+Q8WCp4fgzAvPecs1xBZGgAGjh+6dQf3B9/1DBZA0Tay 0rUYWeyGkus0VA9e+FKBNvM2z2TsVD1WABAlSReOaCyFFTC9x/Q2dZgbhjDHNnKBtVjy vW18aFAP8fveBEqRSWMCJ0vAZpsSmUvFycOnkNUdnwROwSKjOuzDQWp3rCKR09YENus6 5LkQ== 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=dfqcFbTJ9PbfrLTZcVQJecfBGXm3vnW3Frswd5dtiKw=; fh=xT0fk5oP7GynPGhPPBTvnZU2JufV+z3QxPf9rqHlfVI=; b=gWLFHqAgGeDvBRgkYT6K6qPLwml27Q+JbhOH1Kdyng8eK7c2E4nRghY/BGCLUpILxZ HnoyzrP80Qi3s2bPOqbA2hUwxgFs1sv3EU8sDhr6jyjrAYPk89NEbYL2D4Y2dje9O8GK luqxtwNFH/t6145YaKHMLcR/hRT96DI2T04i7MJ+VpwX/4SoOT8bkBiR2coMF4oVzohh FPlYEQZ/fYf9/L0wwvDuaPpRiFFg/kpjVnB6YOSHg1i1WSxzYwJk6oN0dWxfNr+8EA0n rCnEz4tPUqGL4/2o5tHDhAkUmW3eDqiloTi7kNpqNQKoB+SyK2jK/F6ZldYoq1t2qywd m2dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P5inWJiN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id hk8-20020a17090b224800b00274c6997c25si2647770pjb.110.2023.10.05.14.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 14:28:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P5inWJiN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8213E8037710; Thu, 5 Oct 2023 14:28:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjJEV2h (ORCPT + 99 others); Thu, 5 Oct 2023 17:28:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjJEV2g (ORCPT ); Thu, 5 Oct 2023 17:28:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14F695 for ; Thu, 5 Oct 2023 14:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696541315; x=1728077315; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ONU1C7tc3rc3AtZ7xkoZa57Ejqtw/z10sNPrapPUHTM=; b=P5inWJiNZXtLnCV6yESd9MzNVg3OFoq0UyR9+UVpcj1tjexGbBLTutr4 jmbRbAUOpQziShCmdx342Getxsp5By/vT2GAD2tiw8zSuoHOWJET+hLoe xlUPm2m0Us/wCXDiniMDDB+NZzJF9c9KJY9sRAAeYsTEaC5ZgeAH8UucW zI3PBD64EBrtVDgkRF4+aNGdUc829a1caysUvey543AmFDp6XuJvRKwQT 8YiHauIhHCgUbuNGh7gd1dJDPdRQEU6C50drILada/cWw7hRkEuNuEWAQ cTtxQT9Nys8QZIifnljoWUAWjaxsBLvlx7OeRODZvHdd5jGB1JpjSYDcp A==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="382496483" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="382496483" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 14:28:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="875701487" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="875701487" Received: from kvsudesh-mobl1.gar.corp.intel.com (HELO box.shutemov.name) ([10.251.222.76]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 14:28:30 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 1D6CA10A12D; Fri, 6 Oct 2023 00:28:28 +0300 (+03) Date: Fri, 6 Oct 2023 00:28:28 +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: <20231005212828.veeekxqc7rwvrbig@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8d0e4e71-0614-618a-0f84-55eeb6d27a6d@amd.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 05 Oct 2023 14:28:47 -0700 (PDT) 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. > > + int pages = size / PAGE_SIZE; > > + > > + /* > > + * Touching memory with shared bit set triggers implicit > > + * conversion to shared. > > + * > > + * Make sure nobody touches the shared range from > > + * now on. > > + * > > + * Bypass unmapping for crash scenario. Unmapping > > + * requires sleepable context, but in crash case kernel > > + * hits the code path with interrupts disabled. > > In case of SNP we will need to temporarily enable interrupts during this > unsharing as we invoke set_memory_encrypted() which then hits a BUG_ON() in > cpa_flush() if interrupts are disabled. Do you really need full set_memory_encrypted()? Can't you do something ligher? -- Kiryl Shutsemau / Kirill A. Shutemov