From nobody Sat Nov 15 14:12:03 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1751472345; cv=none; d=zohomail.com; s=zohoarc; b=Ypr3SjKoegxAb89OUga5WVFqoKi4PtUoTZcmiFA5YIhunB+KtG6jgKnP0VyJlFd2+zJVQ2jzFydqdFy3TaG5derNYRt9JtBE9rv4vfcr+857MfCW99nZxNCuU0CM3jrSNgGEOjUQ91dQfp/E9WEAS9DSuuxijcWOeVe3nHrI0Bs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751472345; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=PEpmHmmKMZALUNtFsXlWn2QaPy0qKIoF+279LkMRjBQ=; b=E/fvFBj3gToPmMEmILAMiBYGBImk9dFrM3iE5QuwazUKDPkUdbE/nkoD6Yo8ntlrIHniubqh6qmABk+0HrZHAGCE/nn8U6TflMuIqwuc8KshxMWgEB3vLCN6qxNzsS3l1IaYcB/LnAuIza6aJVD39DF+2YL/BcIIcdI+9i0Qnl4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751472345161705.1527895569587; Wed, 2 Jul 2025 09:05:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWzxp-0007wb-Lu; Wed, 02 Jul 2025 12:05:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uWzxj-0007nw-PA for qemu-devel@nongnu.org; Wed, 02 Jul 2025 12:05:32 -0400 Received: from [185.176.79.56] (helo=frasgout.his.huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uWzxi-0007tK-2u for qemu-devel@nongnu.org; Wed, 02 Jul 2025 12:05:31 -0400 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4bXPmm2ZgYz6L4xf; Thu, 3 Jul 2025 00:02:32 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id F2A681404D8; Thu, 3 Jul 2025 00:05:25 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 2 Jul 2025 18:05:25 +0200 To: , Michael Tsirkin , Fan Ni CC: , Subject: [PATCH qemu 06/11] hw/mem: cxl_type3: Add DC Region bitmap lock Date: Wed, 2 Jul 2025 17:02:12 +0100 Message-ID: <20250702160219.989731-7-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250702160219.989731-1-Jonathan.Cameron@huawei.com> References: <20250702160219.989731-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Host-Lookup-Failed: Reverse DNS lookup failed for 185.176.79.56 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1751472346615116600 Content-Type: text/plain; charset="utf-8" From: Anisa Su Add a lock on the bitmap of each CXLDCRegion in preparation for the next patch which implements FMAPI Set DC Region Configuration. This command can modify the block size, which means the region's bitmap must be updated accordingly. The lock becomes necessary when commands that add/release extents (meaning they update the bitmap too) are enabled on a different CCI than the CCI on which the FMAPI commands are enabled. Reviewed-by: Fan Ni Signed-off-by: Anisa Su Signed-off-by: Jonathan Cameron --- include/hw/cxl/cxl_device.h | 1 + hw/mem/cxl_type3.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 469e5d872a..96ef9be444 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -540,6 +540,7 @@ typedef struct CXLDCRegion { uint8_t flags; unsigned long *blk_bitmap; uint64_t supported_blk_size_bitmask; + QemuMutex bitmap_lock; /* Following bools make up dsmas flags, as defined in the CDAT */ bool nonvolatile; bool sharable; diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index cdd60079c4..b872a26173 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -692,6 +692,7 @@ static bool cxl_create_dc_regions(CXLType3Dev *ct3d, Er= ror **errp) }; ct3d->dc.total_capacity +=3D region->len; region->blk_bitmap =3D bitmap_new(region->len / region->block_size= ); + qemu_mutex_init(®ion->bitmap_lock); } QTAILQ_INIT(&ct3d->dc.extents); QTAILQ_INIT(&ct3d->dc.extents_pending); @@ -1020,6 +1021,7 @@ void ct3_set_region_block_backed(CXLType3Dev *ct3d, u= int64_t dpa, return; } =20 + QEMU_LOCK_GUARD(®ion->bitmap_lock); bitmap_set(region->blk_bitmap, (dpa - region->base) / region->block_si= ze, len / region->block_size); } @@ -1046,6 +1048,7 @@ bool ct3_test_region_block_backed(CXLType3Dev *ct3d, = uint64_t dpa, * if bits between [dpa, dpa + len) are all 1s, meaning the DPA range = is * backed with DC extents, return true; else return false. */ + QEMU_LOCK_GUARD(®ion->bitmap_lock); return find_next_zero_bit(region->blk_bitmap, nr + nbits, nr) =3D=3D n= r + nbits; } =20 @@ -1067,6 +1070,7 @@ void ct3_clear_region_block_backed(CXLType3Dev *ct3d,= uint64_t dpa, =20 nr =3D (dpa - region->base) / region->block_size; nbits =3D len / region->block_size; + QEMU_LOCK_GUARD(®ion->bitmap_lock); bitmap_clear(region->blk_bitmap, nr, nbits); } =20 --=20 2.48.1