From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795596004; b=PaamJnp3W2yDxkgTqgrhI8th6FR5JhsRmAisSjJ5FbD6SlEk3SwQq1ao/BlqqCKxO2lx PwZ9pMW6h9uzmUFYtdSDWlS7wz0AEbg8TDdKCZi+klES7MQW3TTm51D21NbdheIRqRmi7 pft7agJ0Cg70Pdw3ZfwyZYNLH6mD+PZRoaCSBYXx9RyYqzyiAqEa4xuxs1aVfWaea1LZ5 9VTsh8uI5RsSUl2fggtCZispVqEJkq144FPetL3mLDE+FOm/M7w9Ow0l95IZwv0ABssES T1J2ErG+XJp3NSR/RUW0+u9Z1Hy1L2+0gDNNQAq5OpuD3wy7icIrYq1iSNFbyI4sh1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795596004; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=Cba8fS/ZVsj+QyvAYm2ReLCTwOe+j7JjbC25csY6/oU=; b=eCMSdT1ZlErz0TD8fz0HL3RDrepMvFCsYWa2L9lB//Gwj5P3hSAuiwtNapbxqqdS0md6 dHD//HQQq8TesW2SpLH66xy310o5FFR85bjcSwsPQXCABCCfyx/TiXxDe6gsQqD38GW/e 41Hevir3XkCNnc06KNH+tCaMBO+wUBR1Z7dFEZzsh2gBhkX3ZDj6TFvnve8frPkyf8Wt5 HFGQa6O/iyJBrLxJtfw1KVeqp21C4JFBY6RrPbmJYBTul9JCYOT7gJTBEhBMm0kkmEnis krTf/L522nQ/5u83R4xxJ+bAt5+ivlBYGQJx6xqi3VfN2JiJoq/dld5w6IA+zPBVHfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GMoBgYIv; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC40C606A31E for ; Wed, 25 Nov 2026 08:40:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC40C606A31E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GMoBgYIv DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795596002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cba8fS/ZVsj+QyvAYm2ReLCTwOe+j7JjbC25csY6/oU=; b=GMoBgYIvcUBzRywqLmhMMGJSK411i4cUw//zAYbwhgLK9NctgmjGG3e9TfF/LeWppKrekm OeZS/ONc6hGRZ42+8UHg/r52NBzY/FQdb0sRvqwxrB1y9StCg2CMeKEsHt5/b+fgnBwZ1T SgBZViVX21X4Jy5Yf0rFbkg6JlfHFF4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-6jyNqfDFPs630dUezLSwdg-1; Wed, 25 Nov 2026 08:39:58 +0000 X-MC-Unique: 6jyNqfDFPs630dUezLSwdg-1 X-Mimecast-MFC-AGG-ID: 6jyNqfDFPs630dUezLSwdg_1795595997 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A016C195604E; Wed, 25 Nov 2026 08:39:57 +0000 (UTC) Received: from desktop (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B12841800550; Wed, 25 Nov 2026 08:39:54 +0000 (UTC) From: Alberto Faria To: linux-block@vger.kernel.org Cc: virtualization@lists.linux.dev, "Michael S. Tsirkin" , Jens Axboe , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Paolo Bonzini , Stefan Hajnoczi , Xuan Zhuo , Jason Wang , Alberto Faria Subject: [PATCH v3 2/2] vdpa_sim_blk: add support for FUA writes Date: Wed, 25 Nov 2026 08:39:47 +0000 Message-ID: <20261125083947.263216-3-afaria@redhat.com> In-Reply-To: <20261125083947.263216-1-afaria@redhat.com> References: <20261125083947.263216-1-afaria@redhat.com> X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Expose VIRTIO_BLK_F_REQ_FLAGS and VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA to drivers. The simulator is a ramdisk, so it handles FUA and non-FUA writes in the same way. Signed-off-by: Alberto Faria --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 15 ++++++++++++++- drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 14 +++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 97d437d89524a..bec348d3dd7d1 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -198,7 +198,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, struct vdpa_device *vdpa; struct vdpasim *vdpasim; struct device *dev; - int i, ret = -ENOMEM; + int i, ret = -ENOMEM, ret2; if (!dev_attr->alloc_size) return ERR_PTR(-EINVAL); @@ -209,6 +209,12 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr, if (config->device_features & ~dev_attr->supported_features) return ERR_PTR(-EINVAL); + if (dev_attr->validate_features) { + ret2 = dev_attr->validate_features( + config->device_features); + if (ret2) + return ERR_PTR(ret2); + } dev_attr->supported_features = config->device_features; } @@ -442,11 +448,18 @@ static u64 vdpasim_get_backend_features(const struct vdpa_device *vdpa) static int vdpasim_set_driver_features(struct vdpa_device *vdpa, u64 features) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + int ret; /* DMA mapping must be done by driver */ if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) return -EINVAL; + if (vdpasim->dev_attr.validate_features) { + ret = vdpasim->dev_attr.validate_features(features); + if (ret) + return ret; + } + vdpasim->features = features & vdpasim->dev_attr.supported_features; return 0; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index bb137e4797633..70890974b6e56 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -45,6 +45,7 @@ struct vdpasim_dev_attr { u32 nas; void (*work_fn)(struct vdpasim *vdpasim); + int (*validate_features)(u64 features); void (*get_config)(struct vdpasim *vdpasim, void *config); void (*set_config)(struct vdpasim *vdpasim, const void *config); int (*get_stats)(struct vdpasim *vdpasim, u16 idx, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c index 4d3e36fb59d50..e0ed9eb729cf3 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -32,7 +32,9 @@ (1ULL << VIRTIO_BLK_F_TOPOLOGY) | \ (1ULL << VIRTIO_BLK_F_MQ) | \ (1ULL << VIRTIO_BLK_F_DISCARD) | \ - (1ULL << VIRTIO_BLK_F_WRITE_ZEROES)) + (1ULL << VIRTIO_BLK_F_WRITE_ZEROES) | \ + (1ULL << VIRTIO_BLK_F_REQ_FLAGS) | \ + (1ULL << VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA)) #define VDPASIM_BLK_CAPACITY 0x40000 #define VDPASIM_BLK_SIZE_MAX 0x1000 @@ -371,6 +373,15 @@ static void vdpasim_blk_work(struct vdpasim *vdpasim) vdpasim_schedule_work(vdpasim); } +static int vdpasim_blk_validate_features(u64 features) +{ + if ((features & BIT_ULL(VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA)) && + !(features & BIT_ULL(VIRTIO_BLK_F_REQ_FLAGS))) + return -EINVAL; + + return 0; +} + static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config) { struct virtio_blk_config *blk_config = config; @@ -424,6 +435,7 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, dev_attr.nas = VDPASIM_BLK_AS_NUM; dev_attr.alloc_size = sizeof(struct vdpasim_blk); dev_attr.config_size = sizeof(struct virtio_blk_config); + dev_attr.validate_features = vdpasim_blk_validate_features; dev_attr.get_config = vdpasim_blk_get_config; dev_attr.work_fn = vdpasim_blk_work; dev_attr.free = vdpasim_blk_free; -- 2.56.1