Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp393531rdb; Tue, 31 Oct 2023 10:14:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYyI4H2riaTp4fiqkWSX3bkZrHk9oxSLQhMlnUiDXTObDQ/10Whe+Hu74v58vQn6fct7x4 X-Received: by 2002:a05:6a00:1795:b0:6be:4b8:c864 with SMTP id s21-20020a056a00179500b006be04b8c864mr16578371pfg.5.1698772447608; Tue, 31 Oct 2023 10:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698772447; cv=none; d=google.com; s=arc-20160816; b=R+25n1wGUfH0Ss8wTM8CwTke0B/a8xKouf1zLNi1tHpbmWTisVWnxGm1zfwo5ReAZn qcO5VS/XnZP5p25yBVejAB5LpXOx4GYcKMtmX8jdYtbI0KFMmsxgcJkyglPDdPQnb+G7 yGUFqL4QxER6Fo93140j4KC8+YzyFJRabyQLj5+8V8dJIuRcuENeJ/Y710hv5YufamQF cbQdx6LwV80oImzWF6Xudfo9ueBKft8rFdjjMPjkSlVW6PUFfDux2LMbaD8vf3N/7OGu ooouumiMNPiD/Dr0Ve+bCvOYchpGTrbJORN5XXiUz6mNwax6ZAOBDO+H6g7XxkGIA+eC CEpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=C/t7JNbhwzhQJdikrhIXlx5gMjFw0DReJg6ztbL++WE=; fh=rVH6sSEKcJrM62/75GQjBmTikIrojvtLeRw1/iX663I=; b=kDyPGVelDjelpE5ZRHCavtmGzFv3IgZ69wm9vNHFd0Gxz+kAZN7K53artmDZAwiCj5 XH+CTt+0pHWjmWI45G3ffZvZN4Czy9oa/WZ7zHdKlW1ntYX1lpGq554uRGtS+bhr4pDZ NKYLYBuMxOqc8VwfZ9La9eVZ2lxexUJv5uG4U3nxG6eoxbzunX/vLCqCfuouSvcIXL9w Bwbf3PMGIPmHDzT4/UPS0X5XlQnLmtWyJmTYiccsbiPIGthMhfEunGoWWxRQTvnozQtP VBVNwrUwA8VAfNIWOff9rufl8YHkhZFARGjbaJKegvCogTugsBPvqQqQxddBf+YEVAQP 2/5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=10IxAPzw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id t8-20020a63dd08000000b005b938759695si1259252pgg.886.2023.10.31.10.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 10:14:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=10IxAPzw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2052F80CF519; Tue, 31 Oct 2023 10:14:05 -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 S1346739AbjJaRNw (ORCPT + 99 others); Tue, 31 Oct 2023 13:13:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344282AbjJaRNs (ORCPT ); Tue, 31 Oct 2023 13:13:48 -0400 Received: from bee.tesarici.cz (bee.tesarici.cz [77.93.223.253]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E237583; Tue, 31 Oct 2023 10:13:44 -0700 (PDT) Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id C44DB191591; Tue, 31 Oct 2023 18:13:41 +0100 (CET) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=none dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1698772422; bh=C/t7JNbhwzhQJdikrhIXlx5gMjFw0DReJg6ztbL++WE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=10IxAPzwMrq3fzyjn4Yy6eS4qfHbdYe7IRNZD0mpwOaTnGxoXCEtc9ovUmA7qKQxa bILAujyYSUj57eWgAG/0SlZrDFFKCgZl6tARb9KmUFuX464LuQYJ2vbC8vXF6+KRdN /BtOHZ6k++amm6wcBek7W7vrMz1OKy0GYuefG5D+ti+4JYdzQWOp5Ukrci28V0z24x m4dE7HMPfdDSU4IzTHej7S3IHGjRGyWnkLdjQbkJmA5rESgGAeXuU6AaOtcNJceHG9 aMHmEcmX6fyKBj0FVnOkIg+9RzOfAG6Q/5FiIo4khDTB3cnJrSMyOS2figrBY9Itqw 2TO625KybgXsA== Date: Tue, 31 Oct 2023 18:13:40 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: "Edgecombe, Rick P" Cc: "Lutomirski, Andy" , "linux-mm@kvack.org" , "iommu@lists.linux.dev" , "dave.hansen@linux.intel.com" , "thomas.lendacky@amd.com" , "robin.murphy@arm.com" , "Reshetova, Elena" , "kirill.shutemov@linux.intel.com" , "mingo@redhat.com" , "Christopherson,, Sean" , "linux-kernel@vger.kernel.org" , "tglx@linutronix.de" , "Cui, Dexuan" , "Yamahata, Isaku" , "mikelley@microsoft.com" , "m.szyprowski@samsung.com" , "hch@lst.de" , "hpa@zytor.com" , "peterz@infradead.org" , "bp@alien8.de" , "linux-s390@vger.kernel.org" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "x86@kernel.org" Subject: Re: [PATCH 04/10] swiotlb: Use free_decrypted_pages() Message-ID: <20231031181340.30233c17@meshulam.tesarici.cz> In-Reply-To: References: <20231017202505.340906-1-rick.p.edgecombe@intel.com> <20231017202505.340906-5-rick.p.edgecombe@intel.com> <20231031114316.0bfa8d91@meshulam.tesarici.cz> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Tue, 31 Oct 2023 10:14:05 -0700 (PDT) On Tue, 31 Oct 2023 15:54:52 +0000 "Edgecombe, Rick P" wrote: > On Tue, 2023-10-31 at 11:43 +0100, Petr Tesa=C5=99=C3=ADk wrote: > >=20 > > I admit I'm not familiar with the encryption/decryption API, but if a > > __free_pages() is not sufficient here, then it is quite confusing. > > The error label is reached only if set_memory_decrypted() returns > > non-zero. My naive expectation is that the memory is *not* decrypted > > in > > that case and does not require special treatment. Is this assumption > > wrong? =20 >=20 > Yea, the memory can still be decrypted, or partially decrypted.=C2=A0On x= 86, > all the set_memory() calls can fail part way through the work, and they > don't rollback the changes they had made up to that point. Thank you for the explanation. So, after set_memory_decrypted() fails, the pages become Schroedinger-crypted, but since its true state cannot be observed by the guest kernel, it stays as such forever. Sweet. >[...] > > OTOH I believe there is a bug in the logic. The subsequent > > __free_pages() in swiotlb_alloc_tlb() would have to be changed to a > > free_decrypted_pages(). However, I'm proposing a different approach > > to > > address the latter issue here: > >=20 > > https://lore.kernel.org/linux-iommu/20231026095123.222-1-petrtesarik@hu= aweicloud.com/T/ =20 >=20 > Oh, yes, that makes sense. I was planning to send a patch to just leak > the pages if set_memory_decrypted() fails, after my v2 linked above is > accepted. It could have a different label than the phys_limit check > error path added in your linked patch, so that case would still free > the perfectly fine encrypted pages. Hm, should I incorporate this knowledge into a v2 of my patch and address both issues? Petr T