From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36A5E13C8EA for ; Fri, 11 Jul 2025 03:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752203449; cv=none; b=i8Oo/0SCN8gxTzPYikFkeWssLIO7G/7/2BS+DQm9X19GHCPoBf8R1cu8v3FgbfQk8uuy6s2tBkHbtOxeO/+ABOiUsTM5UJGlwKvsLi19KoWWolDfyBdYZCKygpUlwMuPGTrLgjmK0UtBOoNgDUwZ4etmAlUJpJOlo1fkUdlubN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752203449; c=relaxed/simple; bh=L63yaiPGvJ249Id/2RRbHTTI3GJEvsSTxsPiKmpWjPM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=X2ORvO0laszqT2JacOd87Its+JmgtgoTZJaECQD/lPpMNEDYvB7EBFgoySCQZhPfkFDEppd23WeC7SmeiBXLWR/LkgfeAQraUSa2apJF9EtJxnNuIBWp0imc0EjrHDFMl5DZcfdmb8F6M7HWCmlfrJvXwwK2FgIe624tC4UJDfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hbtmI+4T; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hbtmI+4T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752203448; x=1783739448; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=L63yaiPGvJ249Id/2RRbHTTI3GJEvsSTxsPiKmpWjPM=; b=hbtmI+4TVlHVTwd5TKmHpRi/YGIcHYrygR7nhkTVwvUO/gx1c7K7lEj/ X6iM7wmEyC4F0Sp2gAztShsNU4wkWjQaNds37L4Gcu7Fpgd7AF11G4Mil MaPcjatWT2Z6OZ3FZrWyVyt0pSZfrAsOkhw1xZM49itWH9X/bmlBWVRF7 S6rn1UOjIP3/195h6YsPYVpqO/IbYubIGm0kM6mBGNsZGZL07AoYKqq8i 8vmeq/E53sysVde16wL48MRxRg/MamdPOXzZJLR1rV60mcD6zts3MRE0O evPI1ou7hBJgvWJh90eLfnFPozKrIGCnMIQmzyRIxVo64AODv6W3xKhIm Q==; X-CSE-ConnectionGUID: 5yV8wXgxRTKjHupo0oVaBQ== X-CSE-MsgGUID: eGG/oKyjQ6GDbU5g3PPFqQ== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="42129626" X-IronPort-AV: E=Sophos;i="6.16,302,1744095600"; d="scan'208";a="42129626" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2025 20:10:47 -0700 X-CSE-ConnectionGUID: nDP+ywDzQuySZNBwEIv3mQ== X-CSE-MsgGUID: NHeP0DHvRL6QFpIo7d1iqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,302,1744095600"; d="scan'208";a="155675431" Received: from allen-sbox.sh.intel.com (HELO [10.239.159.30]) ([10.239.159.30]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2025 20:10:43 -0700 Message-ID: Date: Fri, 11 Jul 2025 11:09:00 +0800 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/1] iommu/sva: Invalidate KVA range on kernel TLB flush To: Peter Zijlstra Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Jason Gunthorpe , Jann Horn , Vasant Hegde , Dave Hansen , Alistair Popple , Uladzislau Rezki , Jean-Philippe Brucker , Andy Lutomirski , "Tested-by : Yi Lai" , iommu@lists.linux.dev, security@kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20250709062800.651521-1-baolu.lu@linux.intel.com> <20250710135432.GO1613376@noisy.programming.kicks-ass.net> <20250710155319.GK1613633@noisy.programming.kicks-ass.net> Content-Language: en-US From: Baolu Lu In-Reply-To: <20250710155319.GK1613633@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/10/25 23:53, Peter Zijlstra wrote: > On Thu, Jul 10, 2025 at 03:54:32PM +0200, Peter Zijlstra wrote: > >>> @@ -132,8 +136,15 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm >>> if (ret) >>> goto out_free_domain; >>> domain->users = 1; >>> - list_add(&domain->next, &mm->iommu_mm->sva_domains); >>> >>> + if (list_empty(&iommu_mm->sva_domains)) { >>> + scoped_guard(spinlock_irqsave, &iommu_mms_lock) { >>> + if (list_empty(&iommu_sva_mms)) >>> + static_branch_enable(&iommu_sva_present); >>> + list_add(&iommu_mm->mm_list_elm, &iommu_sva_mms); >>> + } >>> + } >>> + list_add(&domain->next, &iommu_mm->sva_domains); >>> out: >>> refcount_set(&handle->users, 1); >>> mutex_unlock(&iommu_sva_lock); >>> @@ -175,6 +186,15 @@ void iommu_sva_unbind_device(struct iommu_sva *handle) >>> list_del(&domain->next); >>> iommu_domain_free(domain); >>> } >>> + >>> + if (list_empty(&iommu_mm->sva_domains)) { >>> + scoped_guard(spinlock_irqsave, &iommu_mms_lock) { >>> + list_del(&iommu_mm->mm_list_elm); >>> + if (list_empty(&iommu_sva_mms)) >>> + static_branch_disable(&iommu_sva_present); >>> + } >>> + } >>> + >>> mutex_unlock(&iommu_sva_lock); >>> kfree(handle); >>> } >> >> This seems an odd coding style choice; why the extra unneeded >> indentation? That is, what's wrong with: >> >> if (list_empty()) { >> guard(spinlock_irqsave)(&iommu_mms_lock); >> list_del(); >> if (list_empty() >> static_branch_disable(); >> } > > Well, for one, you can't do static_branch_{en,dis}able() from atomic > context... > > Was this ever tested? I conducted unit tests for vmalloc()/vfree() scenarios, and Yi performed fuzzing tests. We have not observed any warning messages. Perhaps static_branch_disable() is not triggered in the test cases? Thanks, baolu