From patchwork Mon Dec 5 08:41:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2133839wrr; Mon, 5 Dec 2022 00:44:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6LiaIIkFz5+P0tyOKHPdznrJWPB91lKAjeXQSAKH1NakxHkyTGjQQAirsIjBFdocJfebJY X-Received: by 2002:a17:90b:1997:b0:219:8ee5:a226 with SMTP id mv23-20020a17090b199700b002198ee5a226mr14473291pjb.13.1670229878443; Mon, 05 Dec 2022 00:44:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670229878; cv=none; d=google.com; s=arc-20160816; b=mCAAJXyVqiLfovyfIMP4X0Stl2onTu+fHigWIiPfUHN7kH0epJZ4zD+Z1NjvdUe13s SoPVfsNOqx1WIF1wmCo5gPvdl/w1SlEkQuhZn8x2hL3VxKaV/XlFSkItBbuTdHIbrAUh FvVRSwx5X1fQOoJHu2N857o+EjgMjQRE9wghxOo1KWExi+m5r9W5+A0IcTVGpNgZrIHa Z/sDVF1jmpBpZDGOAYVUOO5iCnIvYDNYSQYLvlwiTNlVHN1fxRBWDMUXOU3kkV0wmFaN rgSSOUc9v/hrSv3aE3UgsDhOVGJUvArFfVRB0KHjaeZIGibArlWxJMHSG7rS5Q//xGqA CmKQ== 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:date:subject:cc:to:from :dkim-signature; bh=jxW/Vxu3X7sUPIxDEcWDVrIdRxXj7YBkmL0q7WUBeFw=; b=w8K3rQ5gRAZDtOcegY5fl2FVyIZGR6NbFiDFEEhqPpj/1mbpDGzdLmSr4Xj9XFGTm6 PUgelGRsOwWJxUz1jtu32HwOGqYqX2153g9QTfQjUZICNhK76SePGRwW4oYG1OSDOsdx dTzLMfOXQfwCBxEEGB38NOTV4jonI/PE/I4akTGib9krSSRo7Z3bdOjzvbVlggsq7/nU AVTYk+LG2iT05rY85Zf/2Dp6I3T5r4sadAhoNNF9wSoHn6V2yDp9aOvbT06fYw2rx/Tn MTts7YthwIZHcc1h6w1vRg9b6itCLCFUwOmqIHdac4S4E18CuH5mMds2Y79C/HART8mj JZiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=bLuzMxNG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nk22-20020a17090b195600b001fe1cc52234si13379144pjb.67.2022.12.05.00.44.24; Mon, 05 Dec 2022 00:44:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=bLuzMxNG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbiLEInG (ORCPT + 99 others); Mon, 5 Dec 2022 03:43:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbiLEInB (ORCPT ); Mon, 5 Dec 2022 03:43:01 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BC875FA9 for ; Mon, 5 Dec 2022 00:42:49 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id m4so3227585pls.4 for ; Mon, 05 Dec 2022 00:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jxW/Vxu3X7sUPIxDEcWDVrIdRxXj7YBkmL0q7WUBeFw=; b=bLuzMxNGC9V/pkvZUfNXlaMMl1sDObrP7LLx8vFgFMOrQ8lVdIVp9DbXC9+coJ5Quj 4idlgwdT93B///LhYfpfCTnPwnjxK8TXq0TaFI0A46NPSU07Lnn1KCquLmZJE+bTaUct yxYU1jD0WKMbBKU4b4uE57d/xzCLMxdgGmD5fR65KhXDxJTivXM0OOj7l3Jsqi56iEVV h+ldIx/6Y0xFCYrFARTG99ltCbtx3H0QznGHZ9+CgPJ3Jb//GvjwG3SOGCrpJme0fXe8 kZfCUM0dIalsYXtrtIu0/jNKHA+t53H3Hd8pU6iuZ79+qY6isbpuDe+m/C45TLc/SxTY I4gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jxW/Vxu3X7sUPIxDEcWDVrIdRxXj7YBkmL0q7WUBeFw=; b=QqYfhWz4BpFAPdzSAAiGnUP4vlL+Z7VlgjzIBHxgLpxdA/q99ITq6todf5LbtlF1Kp myAM1nNImstsmcLLz5SIwlGy0R2ShEWupEnKF77xZO2nLWu44CwTJphowiXcNz5BE8GG 5NCxJ7NYq1y2qtbip8JAsVt/Vwj8q+zFG4awIiAF92gyTERc4lXzgZ2ebqqPQRQm/Umi EZcUZ6kn6WaKY3UrTrSoDhWMdx0vYzawUaT7OXuucE2DpAQoWXA5YOdoLVXsmJdN/9Fl AjnDy7nLP91FQomkTs8dndwwRAQOl/ml6w9Tx4c5ncqb2mRFkTxElI06SJPDoeAVdF9c TgDA== X-Gm-Message-State: ANoB5pmIfMRqiL8UW09l0Rxn5To71nHmYQ1khGfJi2B8Ed8UPeryjnAy 4n5bnYk2dcFcUvdwavS003Xm X-Received: by 2002:a17:90a:a095:b0:218:e358:12d2 with SMTP id r21-20020a17090aa09500b00218e35812d2mr58560153pjp.208.1670229769512; Mon, 05 Dec 2022 00:42:49 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id z19-20020aa79493000000b00576670cc170sm5601420pfk.93.2022.12.05.00.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 00:42:49 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/11] genirq/affinity:: Export irq_create_affinity_masks() Date: Mon, 5 Dec 2022 16:41:17 +0800 Message-Id: <20221205084127.535-2-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751362965180809602?= X-GMAIL-MSGID: =?utf-8?q?1751362965180809602?= Export irq_create_affinity_masks() so that some modules can make use of it to implement interrupt affinity spreading mechanism. Signed-off-by: Xie Yongji --- kernel/irq/affinity.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index d9a5c1d65a79..f074a7707c6d 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c @@ -487,6 +487,7 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd) return masks; } +EXPORT_SYMBOL_GPL(irq_create_affinity_masks); /** * irq_calc_affinity_vectors - Calculate the optimal number of vectors From patchwork Mon Dec 5 08:41:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2138002wrr; Mon, 5 Dec 2022 01:00:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vbLu2Bh/E8+pEkUCKJSXRjSfnDWUaMPoKqoped2z1akoyutLZHl0i1GbZ1mWgC2pSITnL X-Received: by 2002:a63:5b64:0:b0:478:ae53:a299 with SMTP id l36-20020a635b64000000b00478ae53a299mr5437753pgm.260.1670230806870; Mon, 05 Dec 2022 01:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670230806; cv=none; d=google.com; s=arc-20160816; b=NZEolm5hXz582nLkTNx991NAW19uClr/4PcOQzmzCdEKBfDE0ZpzdqYEMD/WJRPj4E 7wb83sWdxXKquHBIJhsAJ1+LM6SCM9EB7T9a55dssfjgyR/K7brHiWywU4+V4hfPbL2T aSBhmGuP82Y3B8vH878cMIavTIqua0k1jGAiEIYH1avkfhJbKV2tWqjA5P65shfEgP51 CLPBgoVciDQth0cRnjEIgeIrQIIKNVfdH8tE/ZMmU9qhHndp9lB3zWZ4OaJx1pZ73ctz bLDuXalX4OVtDMANGqBi9g+E2zBt1dVUjLSZMlkekfBjRiyZnXSkM3IN6YMyjA75cl+n 759g== 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:date:subject:cc:to:from :dkim-signature; bh=2mAG9ZtAvBDFdb0SpXtfph5IH524mZezmsFZvVnWTx0=; b=D5GxG0BOdn/wXubbjmA+8h+2Fs+uR6CFVm0k4lAfHYa5sJpDB+JK1xEEEjybVZCTu1 bRFbAF+r31gaz7W4ilnbCZOlQ/e92ZM+fNl0EL607AnFKLQvvWPhpo/sKM1XcBCu3U/5 v407KpfUR/U4CWeWufEOcn7WuE4pz5vYiEStTEYlhD+SB3NTUFqnjxNqQc1VomG2cp9a jk+yURfxK21XaQ4+xy0byID7GK47zeORCwH6hy5rxSOwN5nWSCZi1GnVA6I7twLq882K JYWk6bbzYlduDEreUTx0VbHrgBCWOxU028lYp+VsUleB978r6PoyED3dnWD/APO+RpSV 4xMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=3ggGlnsP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a621584000000b00574e1e34522si13939969pfv.332.2022.12.05.00.59.52; Mon, 05 Dec 2022 01:00:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=3ggGlnsP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232177AbiLEInn (ORCPT + 99 others); Mon, 5 Dec 2022 03:43:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232204AbiLEIn1 (ORCPT ); Mon, 5 Dec 2022 03:43:27 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4523D325 for ; Mon, 5 Dec 2022 00:43:25 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id q71so9883250pgq.8 for ; Mon, 05 Dec 2022 00:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2mAG9ZtAvBDFdb0SpXtfph5IH524mZezmsFZvVnWTx0=; b=3ggGlnsPSSzVuGmzDLhfsID4px8RBvDXR2MtBTOUlUUj+nCEjs70qvGqG3x5w0ts3u AQ6FvDHuPvipUoEIf0aylox+818HjRRusAEnuFl99yMt44Qq/SLVsN3dSXe1NmJHB04e soIc0XL2qW/t20srzEP34qPTmhxqaBzDJqs/WVfPlkfvkiceBVjygmxEO9W/H4y25jfl LK+wsBEcW1TBfZQqpQ9/EL2brHmauZML+SjAJnMRla5BiPbwVluKEBdFWSHdea8rQvMo yvarPiCsKVFzMkVx1uWeInbTXP3xBkoZtN1o9dtTERWPToRV+o9zkmXhX/ifXA4QSYLr 3HSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2mAG9ZtAvBDFdb0SpXtfph5IH524mZezmsFZvVnWTx0=; b=RjK9qznifVyENsku0Gs+f+KBRt2pbLp35GOfgB96JFx+NSEOcpPA7V+Jfr3srzz168 3H3uJfb50uEcnNqgErriJUYzYqbh7xYmy402FoInSg1/zUdLGKV32w5XYgwUuVepnAtO WGIWzpNwvXKJj1zXv1634j2zW9ENBaD7Kk3ehTtWfHh0XBbpVnhzJrt5Q3pDpstRHY3d 7Qpms9wTL5jJ6tAolbYWM67W0LtZxHNfqoVafdZsqOui1hRl6FySes4gALBgKhN1cwKh 0YZ2b/mby9Uvi1ZXQRAgM2KJaprInIx9SjpFjXjfTQyiXTm4pVxVR7pw/0PJ7cx5QiUc D/aA== X-Gm-Message-State: ANoB5pmShh6hN+ml/qsKBwKSDo0QwWRxN3T1HXnV3z+LsrN3cij56Bkq hAUJIVDqxBpg627Pt2JAhBha X-Received: by 2002:a62:6247:0:b0:56b:eda9:f47a with SMTP id w68-20020a626247000000b0056beda9f47amr65941135pfb.84.1670229804801; Mon, 05 Dec 2022 00:43:24 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id 72-20020a62154b000000b0056283e2bdbdsm3851669pfv.138.2022.12.05.00.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 00:43:24 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/11] vdpa: Add set/get_vq_affinity callbacks in vdpa_config_ops Date: Mon, 5 Dec 2022 16:41:18 +0800 Message-Id: <20221205084127.535-3-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751363938215785021?= X-GMAIL-MSGID: =?utf-8?q?1751363938215785021?= This introduces set/get_vq_affinity callbacks in vdpa_config_ops to support interrupt affinity management for vdpa device drivers. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/virtio/virtio_vdpa.c | 28 ++++++++++++++++++++++++++++ include/linux/vdpa.h | 13 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index 9670cc79371d..08084b49e5a1 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -330,6 +330,32 @@ static const char *virtio_vdpa_bus_name(struct virtio_device *vdev) return dev_name(&vdpa->dev); } +static int virtio_vdpa_set_vq_affinity(struct virtqueue *vq, + const struct cpumask *cpu_mask) +{ + struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev); + struct vdpa_device *vdpa = vd_dev->vdpa; + const struct vdpa_config_ops *ops = vdpa->config; + unsigned int index = vq->index; + + if (ops->set_vq_affinity) + return ops->set_vq_affinity(vdpa, index, cpu_mask); + + return 0; +} + +static const struct cpumask * +virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index) +{ + struct vdpa_device *vdpa = vd_get_vdpa(vdev); + const struct vdpa_config_ops *ops = vdpa->config; + + if (ops->get_vq_affinity) + return ops->get_vq_affinity(vdpa, index); + + return NULL; +} + static const struct virtio_config_ops virtio_vdpa_config_ops = { .get = virtio_vdpa_get, .set = virtio_vdpa_set, @@ -342,6 +368,8 @@ static const struct virtio_config_ops virtio_vdpa_config_ops = { .get_features = virtio_vdpa_get_features, .finalize_features = virtio_vdpa_finalize_features, .bus_name = virtio_vdpa_bus_name, + .set_vq_affinity = virtio_vdpa_set_vq_affinity, + .get_vq_affinity = virtio_vdpa_get_vq_affinity, }; static void virtio_vdpa_release_dev(struct device *_d) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 6d0f5e4e82c2..0ff6c9363356 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -247,6 +247,15 @@ struct vdpa_map_file { * @vdev: vdpa device * Returns the iova range supported by * the device. + * @set_vq_affinity: Set the irq affinity of virtqueue (optional) + * @vdev: vdpa device + * @idx: virtqueue index + * @cpu_mask: irq affinity mask + * Returns integer: success (0) or error (< 0) + * @get_vq_affinity: Get the irq affinity of virtqueue (optional) + * @vdev: vdpa device + * @idx: virtqueue index + * Returns the irq affinity mask * @set_group_asid: Set address space identifier for a * virtqueue group (optional) * @vdev: vdpa device @@ -331,6 +340,10 @@ struct vdpa_config_ops { const void *buf, unsigned int len); u32 (*get_generation)(struct vdpa_device *vdev); struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev); + int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx, + const struct cpumask *cpu_mask); + const struct cpumask *(*get_vq_affinity)(struct vdpa_device *vdev, + u16 idx); /* DMA ops */ int (*set_map)(struct vdpa_device *vdev, unsigned int asid, From patchwork Mon Dec 5 08:41:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2135346wrr; Mon, 5 Dec 2022 00:50:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf52JzPQ1K/YzVbCDmFr+OGQC2K11a/cA1iPC3ZQKV+fxW6aPZgYo2HIx6baqg/P+iM6/e+B X-Received: by 2002:a17:906:b819:b0:7c0:f20c:2f64 with SMTP id dv25-20020a170906b81900b007c0f20c2f64mr3607797ejb.230.1670230215024; Mon, 05 Dec 2022 00:50:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670230215; cv=none; d=google.com; s=arc-20160816; b=K8OuDeS6Sn9aD4BiFAxTmS9d1mwFekde03Rovnn4hENVJbat/xMLqkhd9GlajDBMg/ hMD232FaUsEBwamRSW7czFqoV+4lfrNczEbrUQg2A0i5x6lTWvmxm3h6HyK6fsqjmvVe IHJd1ljUmfRTc6f42bAlCZg0S/bTrQbeVNPI0ME5+yPlRZjOTmDcr5XQwAaCVD202t4g /moUFDOAztTHe1P4zRJQ/2ji2sxsz8vO8RV9vwQBlcyOj8UgJyFDgQI3IthTjc13thqB XMMExm7ojSwxur+cBN3LExKEOXqinn+nJHKWhNoTkwxEjw49Q6AYgKIpXoaEuLFgi+Ci fxWQ== 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:date:subject:cc:to:from :dkim-signature; bh=cO+KU63uNOWhYuRIkuFEXhxzLMtKvTfecVGe+9pJx48=; b=xUBiK1kNMCePUhQFpfsLg/LaNUzbcWyTWeUPtK2AkDuy/6hMhQEZrVc3i3VOAwM+F3 Tsuiaf0n+4FknTy+DNCa6gJAychUrHOUngwB4hlSQA0Fv2KNjSQlbNrlGXecsIcjj6h4 ioEyLYEa1KN1r+wsQBwuqxoxLY4IY0YGEjqrd9EmGhX2xgx24Wxa5GPhwvuleU+FZbk/ 6+kTDCIBdadiA/qCNirCdK/NZNES/v1XSZZlwJZ8REqPve3fnw6Y1a9/DLt5QNxJoN2u UCeF7NM8cQK9Tl69p8Oj6lWGKhEgnTZaHJfxOr7SDzRxN/6yMMWMInc8agluDCVzYPWV Of/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=DhvH+Pir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji13-20020a170907980d00b007c098f5e5f4si13273093ejc.233.2022.12.05.00.49.51; Mon, 05 Dec 2022 00:50:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=DhvH+Pir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232221AbiLEInz (ORCPT + 99 others); Mon, 5 Dec 2022 03:43:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbiLEIno (ORCPT ); Mon, 5 Dec 2022 03:43:44 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE7BF6D for ; Mon, 5 Dec 2022 00:43:43 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id jl24so10153412plb.8 for ; Mon, 05 Dec 2022 00:43:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cO+KU63uNOWhYuRIkuFEXhxzLMtKvTfecVGe+9pJx48=; b=DhvH+PirhSMpFBT0JD9NNMmsymRnTivAVV2txwqvLAmz2gZL/tiC09x3ysYplVGVOr rLr3wHTZr0W1MUAL/AegwzZ5IlETMRfuV0hrxpx0sP6rP+s5uOovAtJSDNF/cBLfjR3D k1lqXE1PeD0Pa6oMjZNUyNwMxF4xnJEFazUNyF++JBJabk1UeQc6D/AWxqpcxTWzBkNG 07VLm2boc8fgX9OBw9QbFTAko0AnFCqUi4x07j3nIhWvwit8y5AG45Uar+IlTEzKLCtR 2fqFmUk6M0OtrWZLw4fZuiZx2SnskerlOnQiLdZEeTU4FB8m6gXGti/S6LQeeu5nNdR1 54dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cO+KU63uNOWhYuRIkuFEXhxzLMtKvTfecVGe+9pJx48=; b=D15HZuRRhDygMmjdQzXBAyJewfHwJIjVkKlHGbX2yo2CaOQanAeRkXNCu+K98IkHiu 3GT2zEbZIO+mzN/HdFIesJ8EYjI7piy8zjcjPgXGWNSBmiesqT2MMA4DgNu5E9ZRqHxv 7vz5SV/x3reALf5Cpjsk74YVMuspnoOskUSxz+SMYj6a5Zimpl2sVPTFXSOawmU6FIPf mq4UJnA/AG5Db44tzVhHwQqjb3qI0DSKqWnvgGHkiHHUdIwqjp4IXb24rEd53V6842y1 tLOHKtE+BHWjx7ZuX6DKIrPagz+60M/BuxrEH0nn4S+CY3odD7AEe4U2fqzRYyAdZA0U l+Jg== X-Gm-Message-State: ANoB5ploLnkbUsFBS3/OePDpAOPep4aFxfDmhdmRDPNuG3r/TL9F0sN4 dgx7e5WqWjYicS3kXjzGuaBw X-Received: by 2002:a17:90b:2503:b0:219:baef:3d0 with SMTP id ns3-20020a17090b250300b00219baef03d0mr7903735pjb.95.1670229823405; Mon, 05 Dec 2022 00:43:43 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id n6-20020a170902d2c600b0017c19d7c89bsm10005499plc.269.2022.12.05.00.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 00:43:43 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/11] vdpa: Add set_irq_affinity callback in vdpa_config_ops Date: Mon, 5 Dec 2022 16:41:19 +0800 Message-Id: <20221205084127.535-4-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751363317565243021?= X-GMAIL-MSGID: =?utf-8?q?1751363317565243021?= This introduces set_irq_affinity callback in vdpa_config_ops so that vdpa device driver can get the interrupt affinity hint from the virtio device driver. The interrupt affinity hint would be needed by the interrupt affinity spreading mechanism. Signed-off-by: Xie Yongji --- drivers/virtio/virtio_vdpa.c | 4 ++++ include/linux/vdpa.h | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index 08084b49e5a1..4731e4616ee0 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -275,9 +275,13 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vdev); struct vdpa_device *vdpa = vd_get_vdpa(vdev); const struct vdpa_config_ops *ops = vdpa->config; + struct irq_affinity default_affd = { 0 }; struct vdpa_callback cb; int i, err, queue_idx = 0; + if (ops->set_irq_affinity) + ops->set_irq_affinity(vdpa, desc ? desc : &default_affd); + for (i = 0; i < nvqs; ++i) { if (!names[i]) { vqs[i] = NULL; diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 0ff6c9363356..482ff7d0206f 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -256,6 +256,12 @@ struct vdpa_map_file { * @vdev: vdpa device * @idx: virtqueue index * Returns the irq affinity mask + * @set_irq_affinity: Pass the irq affinity hint from the virtio + * device driver to vdpa driver (optional). + * Needed by the interrupt affinity spreading + * mechanism. + * @vdev: vdpa device + * @desc: irq affinity hint * @set_group_asid: Set address space identifier for a * virtqueue group (optional) * @vdev: vdpa device @@ -344,6 +350,8 @@ struct vdpa_config_ops { const struct cpumask *cpu_mask); const struct cpumask *(*get_vq_affinity)(struct vdpa_device *vdev, u16 idx); + void (*set_irq_affinity)(struct vdpa_device *vdev, + struct irq_affinity *desc); /* DMA ops */ int (*set_map)(struct vdpa_device *vdev, unsigned int asid, From patchwork Mon Dec 5 08:41:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2135409wrr; Mon, 5 Dec 2022 00:50:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf7EbhooGlPOpI5w/+LyoztZ8nP+BCqvk+lX9kzZVtfPdwK4AqVeEeJh2k3yfOXJC6I/xQEh X-Received: by 2002:a17:906:d8ab:b0:7c0:edcd:cf9d with SMTP id qc11-20020a170906d8ab00b007c0edcdcf9dmr4351621ejb.269.1670230227774; Mon, 05 Dec 2022 00:50:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670230227; cv=none; d=google.com; s=arc-20160816; b=dSXky5t+TXBrDN1clMZ0ugGuwMb4HYwuZYXBksLY15plh78pcsIfpufKPA/rrP/B4A IN7wxXJL4B5zBTv1CmziPDceA4CUAzjrh0UluywuYww3DRhJCVj53oTdp8bXB+3CSBRH Za3f1pYgVWxk2kJIdqXKt8mJEwPvbBhPte6ihp3APyvWvNQnshr4UKvvefXW+nq6ySRz 0XKsTlmE0xC8EMP7BNdO+jU9Oy/hhfiDvyyjc2MkURGkzkEAgC3zHNCxTZ5Li9AoCNQp WFfR1F9fc97QGzbiEDgecfeqLN1k5bQNqnOlu0gLCb1kr3FMC6d7vW5854odFTxIluwc l6BA== 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:date:subject:cc:to:from :dkim-signature; bh=KtcX8GDV+5HYnw5oH6dlRpWy9X8S2p+fdAeCWjD/oR8=; b=lFKywR19uI1gWb8tNozzeb7vUWHiSrn5opLngZSfM9jFngrdJ7VMm4MZnSYTP10ENe oTfw+n3gSNc14NxffwLayuBgmW7zAPbVS7jkHHR4r//TCJk7yK+nyGo04pEmPe3G5kAg 259VBDWUF/EeO3qlr3T52fp+gZRsePOcYxEirra6ZXGgJYZspKl5xIx/3+KWYA5bvmWq OPNZnmBiejFSkelVoZk4izecwnn4T2cjOI3xO/uQJhP+xiJwieZU3O1OZPP51S0/irb3 Ijl/gokr8G5QIeo+UE0NsvXea0TdaK1pMoyeWDCdPvaiZPr9lN77tRSkKR2ZXj9XxwA+ RjdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=AogsTePt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020aa7cb4d000000b0046c455300edsi5655917edt.292.2022.12.05.00.50.03; Mon, 05 Dec 2022 00:50:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=AogsTePt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232200AbiLEIoX (ORCPT + 99 others); Mon, 5 Dec 2022 03:44:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232204AbiLEIoL (ORCPT ); Mon, 5 Dec 2022 03:44:11 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80EEE17593 for ; Mon, 5 Dec 2022 00:44:02 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id k79so10676660pfd.7 for ; Mon, 05 Dec 2022 00:44:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KtcX8GDV+5HYnw5oH6dlRpWy9X8S2p+fdAeCWjD/oR8=; b=AogsTePtQjLNKhfa1BOWSNGungtsvGg1xdjBrcn0C/vdAT8PXPSNzcWWyaXSdXx6Kf zxpLv30AJ3gzOWiWeLJ4ebOQyEtwE24/1TY2rPro0i9jJuXpLbKBU4JZn7dcEm4DctPt iAe3wwxRLQoA85eiasCwhFnz9RtWvhPPs1JXmqxFtpFbQQLONDF5eyyi3POcvu6X2v78 tuf2FJ+SRF0qFzHrAMh2B4YfZD55eIz7sVcGOO4XyqhlCc1zDJbqC3YKq2G3+71c11Zg 9xrWVspRooG/0FdoL+S5pTV9ODOpGOn6R3CYXFCa/oSrPxkqSEJwzsfWJF+AJTqwi1RZ wWGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KtcX8GDV+5HYnw5oH6dlRpWy9X8S2p+fdAeCWjD/oR8=; b=1Oizxn7b22m4gVN33FXuUg3B+4mlqfMyFAdpcP15n5OW1bGLxb2DMUMNz6ACp5zXe9 wx/UNtetqhnxxRb5di6RDzdgT32rKDTsqTyq2DOT24NZgjVZ04ewOomvKQANfDZR4lmp JooTbwzhNJG1fqjRc909LBbY1sbZax5ty9iu87tNGafiKF5OeJ+5cscL1pK2aB1oC+2E +6cqZ6a1YSQsJ+DzfbfzFcAJiT37AfsKQ7RQHnEr6uX3Z2huEQdJieFpR/z/iNyuWhcu DVb3RLrLYh1IsDAsLDB+iLARCWAdk/MZ8/F9i2Fig5M8I3DLhzlcxa+rb1fHDcuXOOVT 7RIg== X-Gm-Message-State: ANoB5pkCDQKIpbxNe4laB2EUvhPHhBnfYUWwWLVHoMK9O1zBMHGPZVeJ 0pTo3x28Dh9JNtKPecNYJk5z X-Received: by 2002:a05:6a00:2186:b0:575:d7f8:40ad with SMTP id h6-20020a056a00218600b00575d7f840admr24477242pfi.50.1670229841959; Mon, 05 Dec 2022 00:44:01 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id c73-20020a624e4c000000b00575448ab0fdsm9312479pfb.114.2022.12.05.00.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 00:44:01 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/11] vduse: Refactor allocation for vduse virtqueues Date: Mon, 5 Dec 2022 16:41:20 +0800 Message-Id: <20221205084127.535-5-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751363331377573419?= X-GMAIL-MSGID: =?utf-8?q?1751363331377573419?= Allocate memory for vduse virtqueues one by one instead of doing one allocation for all of them. This is a preparation for adding sysfs interface for virtqueues. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 98 ++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 35dceee3ed56..37809bfcb7ef 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -76,7 +76,7 @@ struct vduse_umem { struct vduse_dev { struct vduse_vdpa *vdev; struct device *dev; - struct vduse_virtqueue *vqs; + struct vduse_virtqueue **vqs; struct vduse_iova_domain *domain; char *name; struct mutex lock; @@ -434,7 +434,7 @@ static void vduse_dev_reset(struct vduse_dev *dev) flush_work(&dev->inject); for (i = 0; i < dev->vq_num; i++) { - struct vduse_virtqueue *vq = &dev->vqs[i]; + struct vduse_virtqueue *vq = dev->vqs[i]; vq->ready = false; vq->desc_addr = 0; @@ -466,7 +466,7 @@ static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx, u64 device_area) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; vq->desc_addr = desc_area; vq->driver_addr = driver_area; @@ -500,7 +500,7 @@ static void vduse_vq_kick_work(struct work_struct *work) static void vduse_vdpa_kick_vq(struct vdpa_device *vdpa, u16 idx) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; if (!eventfd_signal_allowed()) { schedule_work(&vq->kick); @@ -513,7 +513,7 @@ static void vduse_vdpa_set_vq_cb(struct vdpa_device *vdpa, u16 idx, struct vdpa_callback *cb) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; spin_lock(&vq->irq_lock); vq->cb.callback = cb->callback; @@ -524,7 +524,7 @@ static void vduse_vdpa_set_vq_cb(struct vdpa_device *vdpa, u16 idx, static void vduse_vdpa_set_vq_num(struct vdpa_device *vdpa, u16 idx, u32 num) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; vq->num = num; } @@ -533,7 +533,7 @@ static void vduse_vdpa_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; vq->ready = ready; } @@ -541,7 +541,7 @@ static void vduse_vdpa_set_vq_ready(struct vdpa_device *vdpa, static bool vduse_vdpa_get_vq_ready(struct vdpa_device *vdpa, u16 idx) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; return vq->ready; } @@ -550,7 +550,7 @@ static int vduse_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 idx, const struct vdpa_vq_state *state) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) { vq->state.packed.last_avail_counter = @@ -569,7 +569,7 @@ static int vduse_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 idx, struct vdpa_vq_state *state) { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - struct vduse_virtqueue *vq = &dev->vqs[idx]; + struct vduse_virtqueue *vq = dev->vqs[idx]; if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) return vduse_dev_get_vq_state_packed(dev, vq, &state->packed); @@ -624,8 +624,8 @@ static u16 vduse_vdpa_get_vq_num_max(struct vdpa_device *vdpa) int i; for (i = 0; i < dev->vq_num; i++) - if (num_max < dev->vqs[i].num_max) - num_max = dev->vqs[i].num_max; + if (num_max < dev->vqs[i]->num_max) + num_max = dev->vqs[i]->num_max; return num_max; } @@ -863,7 +863,7 @@ static int vduse_kickfd_setup(struct vduse_dev *dev, return -EINVAL; index = array_index_nospec(eventfd->index, dev->vq_num); - vq = &dev->vqs[index]; + vq = dev->vqs[index]; if (eventfd->fd >= 0) { ctx = eventfd_ctx_fdget(eventfd->fd); if (IS_ERR(ctx)) @@ -889,7 +889,7 @@ static bool vduse_dev_is_ready(struct vduse_dev *dev) int i; for (i = 0; i < dev->vq_num; i++) - if (!dev->vqs[i].num_max) + if (!dev->vqs[i]->num_max) return false; return true; @@ -1130,7 +1130,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(config.index, dev->vq_num); - dev->vqs[index].num_max = config.max_size; + dev->vqs[index]->num_max = config.max_size; ret = 0; break; } @@ -1148,7 +1148,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(vq_info.index, dev->vq_num); - vq = &dev->vqs[index]; + vq = dev->vqs[index]; vq_info.desc_addr = vq->desc_addr; vq_info.driver_addr = vq->driver_addr; vq_info.device_addr = vq->device_addr; @@ -1198,7 +1198,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(index, dev->vq_num); - ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index].inject); + ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject); break; } case VDUSE_IOTLB_REG_UMEM: { @@ -1339,6 +1339,49 @@ static const struct file_operations vduse_dev_fops = { .llseek = noop_llseek, }; +static void vduse_dev_deinit_vqs(struct vduse_dev *dev) +{ + int i; + + if (!dev->vqs) + return; + + for (i = 0; i < dev->vq_num; i++) + kfree(dev->vqs[i]); + kfree(dev->vqs); +} + +static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) +{ + int i; + + dev->vq_align = vq_align; + dev->vq_num = vq_num; + dev->vqs = kcalloc(dev->vq_num, sizeof(*dev->vqs), GFP_KERNEL); + if (!dev->vqs) + return -ENOMEM; + + for (i = 0; i < vq_num; i++) { + dev->vqs[i] = kzalloc(sizeof(*dev->vqs[i]), GFP_KERNEL); + if (!dev->vqs[i]) + goto err; + + dev->vqs[i]->index = i; + INIT_WORK(&dev->vqs[i]->inject, vduse_vq_irq_inject); + INIT_WORK(&dev->vqs[i]->kick, vduse_vq_kick_work); + spin_lock_init(&dev->vqs[i]->kick_lock); + spin_lock_init(&dev->vqs[i]->irq_lock); + } + + return 0; +err: + while (i--) + kfree(dev->vqs[i]); + kfree(dev->vqs); + dev->vqs = NULL; + return -ENOMEM; +} + static struct vduse_dev *vduse_dev_create(void) { struct vduse_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL); @@ -1396,7 +1439,7 @@ static int vduse_destroy_dev(char *name) device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); idr_remove(&vduse_idr, dev->minor); kvfree(dev->config); - kfree(dev->vqs); + vduse_dev_deinit_vqs(dev); vduse_domain_destroy(dev->domain); kfree(dev->name); vduse_dev_destroy(dev); @@ -1483,7 +1526,7 @@ ATTRIBUTE_GROUPS(vduse_dev); static int vduse_create_dev(struct vduse_dev_config *config, void *config_buf, u64 api_version) { - int i, ret; + int ret; struct vduse_dev *dev; ret = -EEXIST; @@ -1510,19 +1553,10 @@ static int vduse_create_dev(struct vduse_dev_config *config, dev->config = config_buf; dev->config_size = config->config_size; - dev->vq_align = config->vq_align; - dev->vq_num = config->vq_num; - dev->vqs = kcalloc(dev->vq_num, sizeof(*dev->vqs), GFP_KERNEL); - if (!dev->vqs) - goto err_vqs; - for (i = 0; i < dev->vq_num; i++) { - dev->vqs[i].index = i; - INIT_WORK(&dev->vqs[i].inject, vduse_vq_irq_inject); - INIT_WORK(&dev->vqs[i].kick, vduse_vq_kick_work); - spin_lock_init(&dev->vqs[i].kick_lock); - spin_lock_init(&dev->vqs[i].irq_lock); - } + ret = vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); + if (ret) + goto err_vqs; ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL); if (ret < 0) @@ -1543,7 +1577,7 @@ static int vduse_create_dev(struct vduse_dev_config *config, err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: - kfree(dev->vqs); + vduse_dev_deinit_vqs(dev); err_vqs: vduse_domain_destroy(dev->domain); err_domain: From patchwork Mon Dec 5 08:41:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29603 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2134591wrr; Mon, 5 Dec 2022 00:47:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf77QiCSGIMzxMrUIYXJ5s7UcumQcsvyLwpEmNQrfdlc+VRuxcCtJlOgkzXxqu4yiEsILN83 X-Received: by 2002:a17:90b:258:b0:219:396f:8a09 with SMTP id fz24-20020a17090b025800b00219396f8a09mr37433282pjb.20.1670230039372; Mon, 05 Dec 2022 00:47:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670230039; cv=none; d=google.com; s=arc-20160816; b=d2zwVrv0jv4alHsNz66cMJvT8vaJzwdLlYiy7GFuAfwmt8y+o5jymGPUQR6V4lAn9f oocRtIJLFkk77hd7zLtgksvp0pwRRFQcHapFcgaROBLwAF9cvqXX2nsKoiRnDbUA71lI uOOMe8DGqQT/gLwDTt07Oo2DT+CffclrUR7dMkHk8uhPrKzcn42JFJFwJSv/R8K42IhU sxKg4EeOwTnSdCKp7leE5Fwt/I83keqqnFgg1m1Uc1xI20YOFnnoUgcMCseXd3YKcuUJ QxY3TvXsjs52KpX6VHup7AKPNPRvDUXxHYvP/vqcwBc0ZM10diJiDo91wgSUAIkDtssx 1VYw== 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:date:subject:cc:to:from :dkim-signature; bh=bMI6P3PULWBT8ZMjEJBlSCpH/XnH6SZ3xtd3V98uLe4=; b=LXRHchAGAkxAbpyVladi+PP7nrAlk8+QZMrCioR2Djd8UQEF5ANmK12Gsiv+Bv2Amf QLhnrtTCm6e0fXsFWahpi+x1l6MeDyH1Qqf3bpQM/WXJoBjpB6+r8OMrfh2n0ReYUmES Jh2Q7hIcSHNyVeeZsFTkbrDnLu/WkdXDlvql3o9tGPe/bOp+nwqUM8sBdPIKyg3XKBj/ I8buVwhxgqrl8W/rSmpksgZublWH56lAueiwAEFZfQGJB520JZo901VnBUqJQB+zd3d6 5LjP+H/+p1xvoXdyf8nhG7u6gCHg5EKGAAQS5lp7e5A1Ujy+MhoH22kCUvQOV6DW1Eut jpfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=PPBgn2nT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc22-20020a656d96000000b00478bc014a29si2545366pgb.43.2022.12.05.00.47.06; Mon, 05 Dec 2022 00:47:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=PPBgn2nT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232225AbiLEIo0 (ORCPT + 99 others); Mon, 5 Dec 2022 03:44:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232278AbiLEIoL (ORCPT ); Mon, 5 Dec 2022 03:44:11 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 659FA175B3 for ; Mon, 5 Dec 2022 00:44:05 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id a9so10158805pld.7 for ; Mon, 05 Dec 2022 00:44:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bMI6P3PULWBT8ZMjEJBlSCpH/XnH6SZ3xtd3V98uLe4=; b=PPBgn2nThXaQAvz3fJ6q3csueQxhiYeje3jEXwaxqVnaknt6zCgZsErXIvEMRYKanQ x2gZz91yCUrYuqBzpf27PxAEVTWxXPGgYN77eFYRbG6DwZ34/MJeV8unqJUrwoS3o1+s 4soXq5JRiCZIL3pVAZSD/zfqeufNVWl5Ve7ibwZEK0Z2ERQSRHuFFNvbv7iMIvxoWcVp L2ydVpVvlgcfLrmZNsFCCimFzfwfKEK/N4/DYTngfW+/v0SEOhdMEZ4zK5Kw//EHRe9g scwtq3lOwg9TFfPMGyAU3NSnHfpmm1agd3XE7XpCDsuEJJD4AnOQmpPV7eibHvAVP9U+ DdrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bMI6P3PULWBT8ZMjEJBlSCpH/XnH6SZ3xtd3V98uLe4=; b=Jsudo6q0ujhbcVeB36oxe+v4wvPxDyg+b89ubAvkYsX5CwMFk5gUbJpgrO0k/S0i41 8yiE4igtImfVdI7MepY2LAxbv9KdNvnhOfGSE3QPP/sUjIWVkllC+NxikQ7bR+J5nmHs RF1bNBCBkobyYYuhUn5EuVNK1l+2/hFgep7pF8HDXESHwxLL4xY5R3O7IqTR8ckl6s0l ohc1qaClPpQnye50uS4YB/S31Mdpxubf87JhUgSUrifpXS1CsC0Nyxi5DSKlaT1mNvGB BMnu2lhpZu/9z0W07v2212W4b5cX0U4nZkRLijzExd8RGWUzBT8Y9DibIkLPWuOZCFTM R4DA== X-Gm-Message-State: ANoB5pmxZ7KfuiEygESW2wr7y7ZU4oaSQ+MeEjVX+8vKLJA+XDLCvTHa I3K22EYBVMz4joXxMsfXfNLq X-Received: by 2002:a17:902:f651:b0:188:50c2:89fb with SMTP id m17-20020a170902f65100b0018850c289fbmr47422798plg.130.1670229845294; Mon, 05 Dec 2022 00:44:05 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id p29-20020a635b1d000000b004785d99321asm7887460pgb.86.2022.12.05.00.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 00:44:04 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/11] vduse: Introduce bound workqueue for irq injection Date: Mon, 5 Dec 2022 16:41:21 +0800 Message-Id: <20221205084127.535-6-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751363133494977584?= X-GMAIL-MSGID: =?utf-8?q?1751363133494977584?= This introduces a bound workqueue to support running irq callback in a specified cpu. Signed-off-by: Xie Yongji --- drivers/vdpa/vdpa_user/vduse_dev.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 37809bfcb7ef..d126f3e32a20 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -57,6 +57,7 @@ struct vduse_virtqueue { struct vdpa_callback cb; struct work_struct inject; struct work_struct kick; + int irq_effective_cpu; }; struct vduse_dev; @@ -128,6 +129,7 @@ static struct class *vduse_class; static struct cdev vduse_ctrl_cdev; static struct cdev vduse_cdev; static struct workqueue_struct *vduse_irq_wq; +static struct workqueue_struct *vduse_irq_bound_wq; static u32 allowed_device_id[] = { VIRTIO_ID_BLOCK, @@ -917,7 +919,8 @@ static void vduse_vq_irq_inject(struct work_struct *work) } static int vduse_dev_queue_irq_work(struct vduse_dev *dev, - struct work_struct *irq_work) + struct work_struct *irq_work, + int irq_effective_cpu) { int ret = -EINVAL; @@ -926,7 +929,11 @@ static int vduse_dev_queue_irq_work(struct vduse_dev *dev, goto unlock; ret = 0; - queue_work(vduse_irq_wq, irq_work); + if (irq_effective_cpu == -1) + queue_work(vduse_irq_wq, irq_work); + else + queue_work_on(irq_effective_cpu, + vduse_irq_bound_wq, irq_work); unlock: up_read(&dev->rwsem); @@ -1111,7 +1118,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; } case VDUSE_DEV_INJECT_CONFIG_IRQ: - ret = vduse_dev_queue_irq_work(dev, &dev->inject); + ret = vduse_dev_queue_irq_work(dev, &dev->inject, -1); break; case VDUSE_VQ_SETUP: { struct vduse_vq_config config; @@ -1198,7 +1205,8 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(index, dev->vq_num); - ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject); + ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject, + dev->vqs[index]->irq_effective_cpu); break; } case VDUSE_IOTLB_REG_UMEM: { @@ -1367,6 +1375,7 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) goto err; dev->vqs[i]->index = i; + dev->vqs[i]->irq_effective_cpu = -1; INIT_WORK(&dev->vqs[i]->inject, vduse_vq_irq_inject); INIT_WORK(&dev->vqs[i]->kick, vduse_vq_kick_work); spin_lock_init(&dev->vqs[i]->kick_lock); @@ -1855,12 +1864,15 @@ static int vduse_init(void) if (ret) goto err_cdev; + ret = -ENOMEM; vduse_irq_wq = alloc_workqueue("vduse-irq", WQ_HIGHPRI | WQ_SYSFS | WQ_UNBOUND, 0); - if (!vduse_irq_wq) { - ret = -ENOMEM; + if (!vduse_irq_wq) goto err_wq; - } + + vduse_irq_bound_wq = alloc_workqueue("vduse-irq-bound", WQ_HIGHPRI, 0); + if (!vduse_irq_bound_wq) + goto err_bound_wq; ret = vduse_domain_init(); if (ret) @@ -1874,6 +1886,8 @@ static int vduse_init(void) err_mgmtdev: vduse_domain_exit(); err_domain: + destroy_workqueue(vduse_irq_bound_wq); +err_bound_wq: destroy_workqueue(vduse_irq_wq); err_wq: cdev_del(&vduse_cdev); @@ -1893,6 +1907,7 @@ static void vduse_exit(void) { vduse_mgmtdev_exit(); vduse_domain_exit(); + destroy_workqueue(vduse_irq_bound_wq); destroy_workqueue(vduse_irq_wq); cdev_del(&vduse_cdev); device_destroy(vduse_class, vduse_major); From patchwork Mon Dec 5 08:58:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2140518wrr; Mon, 5 Dec 2022 01:05:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5wT9peg0yk++2mWRSZU/1m0vs/uCTbi5YopbyzacDfZTJaRPIFOpHcBbdZSDzX/uR/BSr+ X-Received: by 2002:a17:907:6d12:b0:7b2:bb8c:5398 with SMTP id sa18-20020a1709076d1200b007b2bb8c5398mr56666981ejc.573.1670231135949; Mon, 05 Dec 2022 01:05:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670231135; cv=none; d=google.com; s=arc-20160816; b=ubeWWYnkV53/cGlBBJw00W4D1/oG7HqOaKS6ABLcTdl/BhIrqMp8ZurW1cW08mcD+W X9hNHwQA98GfvB33Td7RX/30GcLFmQE8/pivH1hkfvTmGhHBzO4EGSv1hNhPQiMC1FTC CZkJAaFYsaIbG8t+89EDfKGmUiFmLUGNxBOZkT3Qie4pMOM5ZVwqHCcIQu8RJAeEhoub e6T2AZF+Zxv84eMWjYmE27uWC0g+7K9eDnIFkzUNQM3kyLOrTY/swywd/PmoUzExUthn xRsvxJqNYQi5KpkyBnNN2aknCPfzGVB3xR3I/eMMFGg4DHHYN1Csp2xsPIGwv8jjAQzG UG4g== 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:date:subject:cc:to:from :dkim-signature; bh=SbUN/Ko04SNzoBySAaB7G+D6Ee//XjJqOiItc7bmihU=; b=nvRTX+Wm7Nq2xPBP+eLcHBeVnp3vZVRhBEmbI1gviXOtOAgp75uXEGb6u6THUVJ2fc WXYgr+44PD28rRvN7qkIPTF0IOjgyABotEM0tTy/rufeps+SYKkrhbVV3tCkAsIkamjs yUezbiVdBostUk1hZC3sbRLTFuTpDjNUDg8FwRa4tM/iPqbE0O/83MyTCrcf2MKojxB5 CzgAul7ISMxjfT3QanxXKXBRufrZOvZ8BD9/fnN7eNLjhXiDCzfavFOdya/fxMyI3jO9 8/6rzVWRyBvhZBvOr8AK9RIVPogdvK3aANi+YmcjVcE+Xu1FASibJFT4304u0KfRT5ib ylGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=PU3O4v2c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cz3-20020a0564021ca300b004573107a5basi10003517edb.352.2022.12.05.01.05.12; Mon, 05 Dec 2022 01:05:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=PU3O4v2c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231671AbiLEJB1 (ORCPT + 99 others); Mon, 5 Dec 2022 04:01:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231904AbiLEJAn (ORCPT ); Mon, 5 Dec 2022 04:00:43 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05DC26426 for ; Mon, 5 Dec 2022 00:59:07 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id q71so9913539pgq.8 for ; Mon, 05 Dec 2022 00:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SbUN/Ko04SNzoBySAaB7G+D6Ee//XjJqOiItc7bmihU=; b=PU3O4v2cQ68yHc6IM8LwdPnVejbvUKQh3EhLMNBFT8BoTrTB5xYC+K7usjaOi6IIdq kmHAB+GDafvHchHAP4Ll8tOEvxqZZCHIYOhdV++DIFj6gF8yGCo9eCANPrCu7cTFYT0h 3iZwyjWwGa/33rxA8gEJ49Lg4x96x9AYDrV6cQZKtqnyt5cIfpb2xEqbMa+yuW3ivl2f QIrVUZFVkD1qRuf015T6SANDjzE+2+A/QHP3EandFeQUgJjmog8pa3PukdCxfo0zNOjp a/5Ua7zJ5uijTSW5rsIx58IxSFQ0/s0Oq2Ou6Qaz5bozmliCAqic7EUZvJV5JY6XjM0B atew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SbUN/Ko04SNzoBySAaB7G+D6Ee//XjJqOiItc7bmihU=; b=GHkYA+CbVXUE4yKpT1S+KQM0w7uT4DuFtXoZyT3AVfihg2plcnBUSJPsN9aAQJkz1v QAM/Iq6T1mqR8ipS6vbD+n/Cw2LN5KgaIsR8DDNX9ifziqhRcs2T9tYwS/U4va0jkF/J hK6DlGVogBG0/14mtHUBemVSQ5vR3f77rdzuDWl2sgfsQEhWzzkCdpIGuCVA1qiR2KkP Ge5GLzx/jZHfH+aTp6+tHYruku2/boe0iyUQ+YBiLPEkkyLHesICZuFqPMYNBaudwSrn NfaR/5wpkMteSdXuS4khxZ/Pd9J1dz50q8+vKcFnh4gy/JxTaqn9xmdc4fNaf8wBa3oi LT+w== X-Gm-Message-State: ANoB5pn1G+NTtjyIxr1aeDnvr9WCO4ihacpDdOxL5nKDXvhD0IEo/Dwx an0YLg30Ij6Zruy6xZWoMTAh X-Received: by 2002:a63:545d:0:b0:476:d44d:358 with SMTP id e29-20020a63545d000000b00476d44d0358mr72628703pgm.521.1670230746520; Mon, 05 Dec 2022 00:59:06 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id e4-20020a056a0000c400b0057709fce782sm910735pfj.54.2022.12.05.00.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 00:59:06 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/11] vduse: Support automatic irq callback affinity Date: Mon, 5 Dec 2022 16:58:41 +0800 Message-Id: <20221205085846.741-1-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751364283685368791?= X-GMAIL-MSGID: =?utf-8?q?1751364283685368791?= This brings current interrupt affinity spreading mechanism to vduse device. We will make use of irq_create_affinity_masks() to create an irq callback affinity mask for each virtqueue of vduse device. Then we will choose the CPU which has the lowest number of interrupt allocated in the affinity mask to run the irq callback. Signed-off-by: Xie Yongji --- drivers/vdpa/vdpa_user/vduse_dev.c | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index d126f3e32a20..90c2896039d9 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,8 @@ struct vduse_virtqueue { struct work_struct inject; struct work_struct kick; int irq_effective_cpu; + struct cpumask irq_affinity; + spinlock_t irq_affinity_lock; }; struct vduse_dev; @@ -123,6 +126,7 @@ struct vduse_control { static DEFINE_MUTEX(vduse_lock); static DEFINE_IDR(vduse_idr); +static DEFINE_PER_CPU(unsigned long, vduse_allocated_irq); static dev_t vduse_major; static struct class *vduse_class; @@ -710,6 +714,49 @@ static u32 vduse_vdpa_get_generation(struct vdpa_device *vdpa) return dev->generation; } +static void vduse_vq_update_effective_cpu(struct vduse_virtqueue *vq) +{ + unsigned int cpu, best_cpu; + unsigned long allocated, allocated_min = UINT_MAX; + + spin_lock(&vq->irq_affinity_lock); + + best_cpu = vq->irq_effective_cpu; + if (best_cpu != -1) + per_cpu(vduse_allocated_irq, best_cpu) -= 1; + + for_each_cpu(cpu, &vq->irq_affinity) { + allocated = per_cpu(vduse_allocated_irq, cpu); + if (!cpu_online(cpu) || allocated >= allocated_min) + continue; + + best_cpu = cpu; + allocated_min = allocated; + } + vq->irq_effective_cpu = best_cpu; + per_cpu(vduse_allocated_irq, best_cpu) += 1; + + spin_unlock(&vq->irq_affinity_lock); +} + +static void vduse_vdpa_set_irq_affinity(struct vdpa_device *vdpa, + struct irq_affinity *desc) +{ + struct vduse_dev *dev = vdpa_to_vduse(vdpa); + struct irq_affinity_desc *affd = NULL; + int i; + + affd = irq_create_affinity_masks(dev->vq_num, desc); + if (!affd) + return; + + for (i = 0; i < dev->vq_num; i++) { + cpumask_copy(&dev->vqs[i]->irq_affinity, &affd[i].mask); + vduse_vq_update_effective_cpu(dev->vqs[i]); + } + kfree(affd); +} + static int vduse_vdpa_set_map(struct vdpa_device *vdpa, unsigned int asid, struct vhost_iotlb *iotlb) @@ -760,6 +807,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = { .get_config = vduse_vdpa_get_config, .set_config = vduse_vdpa_set_config, .get_generation = vduse_vdpa_get_generation, + .set_irq_affinity = vduse_vdpa_set_irq_affinity, .reset = vduse_vdpa_reset, .set_map = vduse_vdpa_set_map, .free = vduse_vdpa_free, @@ -1380,6 +1428,8 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) INIT_WORK(&dev->vqs[i]->kick, vduse_vq_kick_work); spin_lock_init(&dev->vqs[i]->kick_lock); spin_lock_init(&dev->vqs[i]->irq_lock); + spin_lock_init(&dev->vqs[i]->irq_affinity_lock); + cpumask_setall(&dev->vqs[i]->irq_affinity); } return 0; From patchwork Mon Dec 5 09:02:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2148192wrr; Mon, 5 Dec 2022 01:30:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf64YnjkVDpryBBDDBiqWXh+W1RoLb/TFqPnSk0oz6heWCvv/Ref6bo5QzkkWbQiEDUpghor X-Received: by 2002:a63:530f:0:b0:476:bfca:38ad with SMTP id h15-20020a63530f000000b00476bfca38admr58053910pgb.576.1670232646596; Mon, 05 Dec 2022 01:30:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670232646; cv=none; d=google.com; s=arc-20160816; b=KxOvZEQ76oHs7i9vuve0yXuPMvri67isC09J8pKgXqDgKGsbmoz3BkkNOWjkAvI2iF t/lE0dwC3491FX5vRNSxVE1bGCIjwIGyOLqe+04cKB7E3wehqagfAmCz+GYOnzRNR0ST Eyiafzm73O6N5hu5+RK66sj4qzX+kaOF3llzjzDELdAbU/h6pbnvXSAu2i6u9LV0iXhI yLF6ah/sE6+vtqzrlhxxVFjcDN68sVyGYGXTjboEkTGrLqg2V0Bq2wxyqjkUAdkJIwtt 2XqHibeoVXnX8DS5F8B0hVr47wWJGgYj5yttsd2KK2XUNiwHrnq/48DLHov2TbY7kmHK 7qEQ== 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:date:subject:cc:to:from :dkim-signature; bh=OshPsK9iOwiWj6ej55hHDAz7FEiazePp8poCkCFNGxA=; b=Ek3LvEiSM6vf1dNoJjRMIGWz7HVlbVZbNp9aHXp+NvQQKS7ghRoWkBgupdW+Qk6TEo aaWamlO8WqPBNhue0jpOLqJ7pMeUEcB6GhYapd1kHOssA5y/ARVaNNzpPcCCH5uPMsFz jp7Teu8CsDDeLSObS0WSL4KeqRAy3KhHyti6El4Sxzj5tZWZlWYcpIyI1Vs8wQe60w+L wz6ZhOSbeFkSDokrEWhLHlshuKMAztlccDLIQSQaO5LZefICkonQvY7tJBOHjzXci6Uj L+QJnO/Rf7nuH3CHDqo1ekRRcRZck/khMKEvoxu0MmrBF0tF+iPW1JIkbbWAD3M4KnbX SW5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=68OaXWJD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a65580e000000b0046ae2a8ea9csi14334166pgr.733.2022.12.05.01.30.33; Mon, 05 Dec 2022 01:30:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=68OaXWJD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232491AbiLEJEF (ORCPT + 99 others); Mon, 5 Dec 2022 04:04:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbiLEJDT (ORCPT ); Mon, 5 Dec 2022 04:03:19 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B9CBF70 for ; Mon, 5 Dec 2022 01:02:55 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so2201768pjj.2 for ; Mon, 05 Dec 2022 01:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OshPsK9iOwiWj6ej55hHDAz7FEiazePp8poCkCFNGxA=; b=68OaXWJDpO+ve8DUgOhH/3nWT7HjsJAD5UDl3Z+88p6a5Vim4LqU1I2tSIIwxP8fgj 1fkb9Q8lYcK2DuDZMQO1dwegp5qlvIqCfvwMsbQvubp+K5E7EDWHXEyo7UsaL1X9eVg3 oq4vPdFpyQX4lQiu2ABhqckhKOoKHF5+UPgwbAqOvgpu3SoEV3GzdloDSxeHlJePZIp4 02JJ+j2kb/s9r6Kz0EFxeJII6nBQnMP2cjglR5mURMsjMRI4o4lQ6aL76i7+Tr6tqays B9WYsOelbTKR74i51N6FQ8RxLMrjHDaLkobY6/PmmpOcbsGsRwvaWJqxP3xtvMqsPEHF nuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OshPsK9iOwiWj6ej55hHDAz7FEiazePp8poCkCFNGxA=; b=hGxb5tMaDyXyEb7T4SGEYZFUAvDAMiPx3us31fHHMjlxTxHP37wZeDVGJlFrmFH6TX MQZxZxl4uF51htLobfEEX3d8+DBUAewQuIqJhac9MhM0rEkyZRU/ylnga8AmA2xJkA/D e1dn+6IqFh076+fcv69S4Q7vAT5uKicN7juvBgCx3nRGlfHuXrYOEskTAg9xKMpULD1i dnlQrpuVXDJKRZc62ur284C8GCt/Hdil8hmph3405EOgGSH0kFg/Vxi/27iKH81U4OTu 71FfJnaz/1FghRjRumS2hflIuITWSc3LnuOw9IC7BrWpX9oxZsOeoCm788+mDopr6ksY 4oaQ== X-Gm-Message-State: ANoB5plGe5IqFmQPA+5eFGwoMhiQCGj8H8uKFg/T+QwpAcz5vmzhc3ID WU0QDEXPZVBFexl/eBPC04NvgNF5Ok0UWxs= X-Received: by 2002:a17:90a:6408:b0:219:a82a:97f3 with SMTP id g8-20020a17090a640800b00219a82a97f3mr10420293pjj.95.1670230974969; Mon, 05 Dec 2022 01:02:54 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id z5-20020aa79585000000b005764a143be3sm6022700pfj.103.2022.12.05.01.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 01:02:54 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/11] vduse: Support set/get_vq_affinity callbacks Date: Mon, 5 Dec 2022 17:02:39 +0800 Message-Id: <20221205090243.791-1-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205084127.535-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751365867592580902?= X-GMAIL-MSGID: =?utf-8?q?1751365867592580902?= Since we already support irq callback affinity management, let's implement the set/get_vq_affinity callbacks to make it possible for the virtio device driver to change or be aware of the affinity. This would make it possible for the virtio-blk driver to build the blk-mq queues based on the irq callback affinity. Signed-off-by: Xie Yongji --- drivers/vdpa/vdpa_user/vduse_dev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 90c2896039d9..6507a78abc9d 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -739,6 +739,28 @@ static void vduse_vq_update_effective_cpu(struct vduse_virtqueue *vq) spin_unlock(&vq->irq_affinity_lock); } +static int vduse_vdpa_set_vq_affinity(struct vdpa_device *vdpa, u16 idx, + const struct cpumask *cpu_mask) +{ + struct vduse_dev *dev = vdpa_to_vduse(vdpa); + + cpumask_copy(&dev->vqs[idx]->irq_affinity, cpu_mask); + vduse_vq_update_effective_cpu(dev->vqs[idx]); + + return 0; +} + +static const struct cpumask * +vduse_vdpa_get_vq_affinity(struct vdpa_device *vdpa, u16 idx) +{ + struct vduse_dev *dev = vdpa_to_vduse(vdpa); + + if (dev->vqs[idx]->irq_effective_cpu == -1) + return NULL; + + return &dev->vqs[idx]->irq_affinity; +} + static void vduse_vdpa_set_irq_affinity(struct vdpa_device *vdpa, struct irq_affinity *desc) { @@ -807,6 +829,8 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = { .get_config = vduse_vdpa_get_config, .set_config = vduse_vdpa_set_config, .get_generation = vduse_vdpa_get_generation, + .set_vq_affinity = vduse_vdpa_set_vq_affinity, + .get_vq_affinity = vduse_vdpa_get_vq_affinity, .set_irq_affinity = vduse_vdpa_set_irq_affinity, .reset = vduse_vdpa_reset, .set_map = vduse_vdpa_set_map, From patchwork Mon Dec 5 09:02:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2143282wrr; Mon, 5 Dec 2022 01:13:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf65fggcPUPLywppsL/t5G/MVH7rjFU3wRM8KaJLlQxf5dzW0XcVe04ARFsLA08SVaxvhdfB X-Received: by 2002:a17:906:882:b0:7ad:e161:b026 with SMTP id n2-20020a170906088200b007ade161b026mr64296211eje.760.1670231633681; Mon, 05 Dec 2022 01:13:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670231633; cv=none; d=google.com; s=arc-20160816; b=Tk+bg+EwJmssPRmcS4FdHzZZmqcGtKlnqNuXhuGzRQWLx5SnoNNRj6AGOvIVbwp0QG +HyVZbU2puqNNnd2iHUEdQZcBGg8u8e4yUddmosBas0VcVJdlfALkg6TsqKwPNVgeTDI SCCGf+AiHzhVkVwG92e1anJaJXNumsSZSLrF/0L8+spZoHyznf9d9E+dyAVIF4+CEf8y t4szg+Zby3hwyHJluqOERzfBB3ddfLoNLbiObmlhQhS9076YeX+fPooqZy/ytKWrQBm8 FwiLLr2dWkM4ZZwKfhr94BjMKR6GR7mPX1GDbC1vhd0jG7Z+cXmZt8ULbgp+FIh8CpR2 lEZA== 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:date:subject:cc:to:from :dkim-signature; bh=J3uhbY4lwU4y8TtkVG7MMu4/x3HSVOU76J0Hc6lokBs=; b=ZXBzc6GCYu9IIQuv0jl9LYSrqjNbDrlcV0VRnnwnElw2O3qyv739u0RjgLEE+SEu3S LvhqHlqgR8jrTdCAJhqWiyDEVaJi6c3zfKMdTbrMBQDLeV4MXKNSENN/d2r6rcXS8+vm GwUbWEYJ0JWhArVP791rhMaucC9D2LXh5wdlqJ8J9Xa4KsK2Gz/FnsspxTRSxEDdAhjX zureqB4fB1x3DeTWC+Il07llybWKSdZCyZ8bSsf53m9shbMyD9ycutZsJSV2S5gqfR1v Gi0ir+3Wq3+VqNoHaubpvABKQ2yC+/IDfXe8QDTnT1o/r88fu4QyK7Hy2srMRdgLVwZv dPUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YuTQGk3J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rn5-20020a170906d92500b0078d450cbb02si198732ejb.452.2022.12.05.01.13.25; Mon, 05 Dec 2022 01:13:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YuTQGk3J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232501AbiLEJEL (ORCPT + 99 others); Mon, 5 Dec 2022 04:04:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbiLEJD1 (ORCPT ); Mon, 5 Dec 2022 04:03:27 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACB84DE9D for ; Mon, 5 Dec 2022 01:02:58 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so14144342pjs.4 for ; Mon, 05 Dec 2022 01:02:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J3uhbY4lwU4y8TtkVG7MMu4/x3HSVOU76J0Hc6lokBs=; b=YuTQGk3JDlJpZX2nnGWEHpINdwahi2g6qU1MNJgM2MuruYoqwUnhnDun/NqZtLGx85 2scII5gmfhp1Lk+HDUCM2Pub+Gqi/ejEos4w2gCXkQFlLCPyw5ynvAlG0RIT840XrQIs PrLbfUy4J2mmDLwLYOpZwtTnZofyMIpsmF4xghhYyW+dhHky5jqdWBI7bMg3LjOwqyV7 1lzzh3WXgVL1pVvRGf0aQH+cjKkR9K6Ps5kt1edzHHy9eZm/wltZ6q5HqGok3/2BQoCV 37OTLymIRuSGViC1xjPJZ8U9Nj888vfA9abrkYMQicZf7W4ljlR99reJfTUvwiCxwbXK oOQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J3uhbY4lwU4y8TtkVG7MMu4/x3HSVOU76J0Hc6lokBs=; b=BmJXs27fI43Qhc0+vNKOD6lop2aO7JTz2IVgods1grSVqMoigWZbAM51fOcAU/lvQu vYK/KgvkLG6Bq0SIaDS04BTwi6svULqXhyFIO4PF8wJC5Zk21Ru+tPnOlNNKpZpBvnVX vHhtnS4PU3alsExX9DPnAxzmtwRgZu4mNXluri4lVlCqruiY3TD7T5N+zaZP2fe6tKfH WWTtslxSR9rNeajzxnj5PhNxQtpiz9HqUKaUBWLBTYLdCiGCe8I1ioInNPvJIlkJL7wD 7P504zAHePHY/Vop0sgug5j1TXim30h1yC4S0AwrLdB/Vb+ygoZEGsVJWWDZMV6zHSwa 7yqg== X-Gm-Message-State: ANoB5pmSgzqoGYbSjKFtrNW/3m7XxassBQ3zwr7GuZVih9jEyflfENmZ 3KF93d1sluJM7T/4daPO/qAR X-Received: by 2002:a17:90b:11d6:b0:219:ce92:17a1 with SMTP id gv22-20020a17090b11d600b00219ce9217a1mr4975256pjb.235.1670230978187; Mon, 05 Dec 2022 01:02:58 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id y14-20020a62640e000000b0056bb4bbfb9bsm6709398pfb.95.2022.12.05.01.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 01:02:57 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/11] vduse: Add sysfs interface for irq callback affinity Date: Mon, 5 Dec 2022 17:02:40 +0800 Message-Id: <20221205090243.791-2-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205090243.791-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> <20221205090243.791-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751364805323173403?= X-GMAIL-MSGID: =?utf-8?q?1751364805323173403?= Add sysfs interface for each vduse virtqueue to show the affinity and effective affinity for irq callback. And we can also use this interface to change the effective affinity which must be a subset of the irq callback affinity mask for the virtqueue. This might be useful for performance tuning when the irq callback affinity mask contains more than one CPU. Signed-off-by: Xie Yongji --- drivers/vdpa/vdpa_user/vduse_dev.c | 148 ++++++++++++++++++++++++++--- 1 file changed, 137 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 6507a78abc9d..c65f84100e30 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -61,6 +61,7 @@ struct vduse_virtqueue { int irq_effective_cpu; struct cpumask irq_affinity; spinlock_t irq_affinity_lock; + struct kobject kobj; }; struct vduse_dev; @@ -1419,6 +1420,120 @@ static const struct file_operations vduse_dev_fops = { .llseek = noop_llseek, }; +static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) +{ + return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity)); +} + +static ssize_t irq_cb_effective_affinity_show(struct vduse_virtqueue *vq, + char *buf) +{ + struct cpumask all_mask = CPU_MASK_ALL; + const struct cpumask *mask = &all_mask; + + if (vq->irq_effective_cpu != -1) + mask = get_cpu_mask(vq->irq_effective_cpu); + + return sprintf(buf, "%*pb\n", cpumask_pr_args(mask)); +} + +static ssize_t irq_cb_effective_affinity_store(struct vduse_virtqueue *vq, + const char *buf, size_t count) +{ + cpumask_var_t new_value; + int ret; + + if (!zalloc_cpumask_var(&new_value, GFP_KERNEL)) + return -ENOMEM; + + ret = cpumask_parse(buf, new_value); + if (ret) + goto free_mask; + + ret = -EINVAL; + if (!cpumask_intersects(new_value, &vq->irq_affinity)) + goto free_mask; + + spin_lock(&vq->irq_affinity_lock); + + if (vq->irq_effective_cpu != -1) + per_cpu(vduse_allocated_irq, vq->irq_effective_cpu) -= 1; + + vq->irq_effective_cpu = cpumask_first(new_value); + per_cpu(vduse_allocated_irq, vq->irq_effective_cpu) += 1; + + spin_unlock(&vq->irq_affinity_lock); + ret = count; + +free_mask: + free_cpumask_var(new_value); + return ret; +} + +struct vq_sysfs_entry { + struct attribute attr; + ssize_t (*show)(struct vduse_virtqueue *vq, char *buf); + ssize_t (*store)(struct vduse_virtqueue *vq, const char *buf, + size_t count); +}; + +static struct vq_sysfs_entry irq_cb_affinity_attr = __ATTR_RO(irq_cb_affinity); +static struct vq_sysfs_entry irq_cb_effective_affinity_attr = + __ATTR_RW(irq_cb_effective_affinity); + +static struct attribute *vq_attrs[] = { + &irq_cb_affinity_attr.attr, + &irq_cb_effective_affinity_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(vq); + +static ssize_t vq_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct vduse_virtqueue *vq = container_of(kobj, + struct vduse_virtqueue, kobj); + struct vq_sysfs_entry *entry = container_of(attr, + struct vq_sysfs_entry, attr); + + if (!entry->show) + return -EIO; + + return entry->show(vq, buf); +} + +static ssize_t vq_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) +{ + struct vduse_virtqueue *vq = container_of(kobj, + struct vduse_virtqueue, kobj); + struct vq_sysfs_entry *entry = container_of(attr, + struct vq_sysfs_entry, attr); + + if (!entry->store) + return -EIO; + + return entry->store(vq, buf, count); +} + +static const struct sysfs_ops vq_sysfs_ops = { + .show = vq_attr_show, + .store = vq_attr_store, +}; + +static void vq_release(struct kobject *kobj) +{ + struct vduse_virtqueue *vq = container_of(kobj, + struct vduse_virtqueue, kobj); + kfree(vq); +} + +static struct kobj_type vq_type = { + .release = vq_release, + .sysfs_ops = &vq_sysfs_ops, + .default_groups = vq_groups, +}; + static void vduse_dev_deinit_vqs(struct vduse_dev *dev) { int i; @@ -1427,13 +1542,13 @@ static void vduse_dev_deinit_vqs(struct vduse_dev *dev) return; for (i = 0; i < dev->vq_num; i++) - kfree(dev->vqs[i]); + kobject_put(&dev->vqs[i]->kobj); kfree(dev->vqs); } static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) { - int i; + int ret, i; dev->vq_align = vq_align; dev->vq_num = vq_num; @@ -1443,8 +1558,10 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) for (i = 0; i < vq_num; i++) { dev->vqs[i] = kzalloc(sizeof(*dev->vqs[i]), GFP_KERNEL); - if (!dev->vqs[i]) + if (!dev->vqs[i]) { + ret = -ENOMEM; goto err; + } dev->vqs[i]->index = i; dev->vqs[i]->irq_effective_cpu = -1; @@ -1454,15 +1571,23 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) spin_lock_init(&dev->vqs[i]->irq_lock); spin_lock_init(&dev->vqs[i]->irq_affinity_lock); cpumask_setall(&dev->vqs[i]->irq_affinity); + + kobject_init(&dev->vqs[i]->kobj, &vq_type); + ret = kobject_add(&dev->vqs[i]->kobj, + &dev->dev->kobj, "vq%d", i); + if (ret) { + kfree(dev->vqs[i]); + goto err; + } } return 0; err: while (i--) - kfree(dev->vqs[i]); + kobject_put(&dev->vqs[i]->kobj); kfree(dev->vqs); dev->vqs = NULL; - return -ENOMEM; + return ret; } static struct vduse_dev *vduse_dev_create(void) @@ -1637,10 +1762,6 @@ static int vduse_create_dev(struct vduse_dev_config *config, dev->config = config_buf; dev->config_size = config->config_size; - ret = vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); - if (ret) - goto err_vqs; - ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL); if (ret < 0) goto err_idr; @@ -1654,14 +1775,19 @@ static int vduse_create_dev(struct vduse_dev_config *config, ret = PTR_ERR(dev->dev); goto err_dev; } + + ret = vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); + if (ret) + goto err_vqs; + __module_get(THIS_MODULE); return 0; +err_vqs: + device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: - vduse_dev_deinit_vqs(dev); -err_vqs: vduse_domain_destroy(dev->domain); err_domain: kfree(dev->name); From patchwork Mon Dec 5 09:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2145765wrr; Mon, 5 Dec 2022 01:22:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TvyC/4CsivS/mSImasP3h4FgWEgJuMcEqZ7ANJYGjQUrrISy7UNdnNBh2ezeJZkzzc586 X-Received: by 2002:a17:906:3fce:b0:7ad:bb54:75d3 with SMTP id k14-20020a1709063fce00b007adbb5475d3mr67833967ejj.484.1670232125542; Mon, 05 Dec 2022 01:22:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670232125; cv=none; d=google.com; s=arc-20160816; b=rk6wk4nReHnIzWg4CRC1CyipzPWbgozYATd0KHN/aFEdZ0+nzG8eVwrbZtUHlHJFqG YFVJTT7qfe/0ctysAAgSLi4fgl6V0LanJq4EPhZnRGmpgEYbwXUhVOvel6p9fFMyEIiI VgGk1wP7HhXCQjuEHoATnbkAxXCER39nNtgKjDw6gFGJF5ZUQa7ymOuoxbv98dJsxTiF 3GT9TkSG3NBFm6abLDmAufDZC+wJyOb0Qmtphphiy33CBuM8mV18m+1okSEZiLkZ2Rdz 5ZBD62OAkhQsl+MTwafwdp/TdySUQXmAIMG7mSpmrdgwXrg49eC9YNaztHvBSVbsoQ5q tjoQ== 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:date:subject:cc:to:from :dkim-signature; bh=0F4aYFXGksQtN5NYEODlVl4Bem8OEWuiuWQxHQeKgGE=; b=fXeFiExdWvHWYXqG8Lu1GV1sM8VjxoHIV5XYGuYeIyWzTQDaPBI0JQfvShFRouy6J3 UyBcMKRilVXtU0a1Cu/8xSbm1ujcRg586CN/W1kR93M17BafqwKItXbNH16icA8EWim0 eBnHaBE+feY6kwSkJ1e37/jSaOwBx/tdLQ7iTZg7m/I5iLwCVB32nmF5YrD0pPFmYgci 9VvR1vFuXeJTkSoP4iciMRSwuR4u7fyGb/mbjYrEOY/TcODkUi57Gw4Le+OQ3x4SJq2O unOL+0AugquTc8IpFq6qBckvH3jYZpW8nMUiwiS/61rifVhxt57kMXhaJaqvU6SxXFR8 5UEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=sSKC7gm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr12-20020a170907720c00b007ae545e330csi7308629ejc.218.2022.12.05.01.21.41; Mon, 05 Dec 2022 01:22:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=sSKC7gm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232517AbiLEJEP (ORCPT + 99 others); Mon, 5 Dec 2022 04:04:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232082AbiLEJD3 (ORCPT ); Mon, 5 Dec 2022 04:03:29 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6161FD31 for ; Mon, 5 Dec 2022 01:03:01 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id q17-20020a17090aa01100b002194cba32e9so14171560pjp.1 for ; Mon, 05 Dec 2022 01:03:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0F4aYFXGksQtN5NYEODlVl4Bem8OEWuiuWQxHQeKgGE=; b=sSKC7gm8zRkAoVolXgWwlic+bvrd4CBsX+FKLhQCPFbXrSE8ntYCq5UdeliPa8D05J 0YMmvSG2P33BN6mUU7ELEG6JrfbhRF5q6JH9ANXTQlFjHhOy/qH8GN0iIozIE0qwBnZN i/GUVYoB21hXkIX/Ky4/JI6FkaPw1vJiqukaLZhqX/A2Hx0RxTIBCib/TbO17+voDGCE EpqTQOBCyn8+IYbWeahD6HmHhb72hjirua9v6ou8Ues8ON0gqGOd3bkxvfeDOox9/T5E OccwffpJ+FahYu+qRoXDRIhhtCVi7gUO+htOEDHcQ4WPtRo5vniEYPlZ5lyGkLZDI4tz MWXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0F4aYFXGksQtN5NYEODlVl4Bem8OEWuiuWQxHQeKgGE=; b=5/+2denMbjJBFJy/IRE/FpHJbzYeZjKwkz0hamAHSySzlkvzmKgPPKhoKPr27ZV13T yLN0YuNpc7Zz3vwpcqJVGB0CuuFIoivei511sihS+RXqDM1y3B/We2UUETMczUTS6EIW mdBvGc7akvx2Ij9RSHVWAdnTmN7qONOjcnHfbBoL1VZZMLFZZ50wEHxh2TxKegxbPWDv zx3MgyrcPeJT89NtXaiSU2KYvo5zwE20pTpQCHqlVKntIlQOIoy5p+xZEZZjpUSQr1pv mbPn9oOzLYz5Cdm35qniBqPLtvssKZO3UAHpZYFfWNqCaEPIF+qWHGvzDY1OtkNYo916 i5GQ== X-Gm-Message-State: ANoB5plmqgdOJglyDv4oybbmnjtnTxZQGxozWaZlAjJQ6frNznAXN2Tv YZrYQkrkwZBGmQzkg6OBZsRo X-Received: by 2002:a17:903:240a:b0:188:abb9:290 with SMTP id e10-20020a170903240a00b00188abb90290mr63732725plo.86.1670230981430; Mon, 05 Dec 2022 01:03:01 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id z189-20020a6365c6000000b00460c67afbd5sm7900683pgb.7.2022.12.05.01.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 01:03:01 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/11] vduse: Add enable_irq_wq sysfs interface for virtqueues Date: Mon, 5 Dec 2022 17:02:41 +0800 Message-Id: <20221205090243.791-3-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205090243.791-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> <20221205090243.791-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751365321676718283?= X-GMAIL-MSGID: =?utf-8?q?1751365321676718283?= Add enable_irq_wq sysfs interface to control whether use workqueue to inject irq or not. The vhost-vdpa case can benefit from it. Signed-off-by: Xie Yongji --- drivers/vdpa/vdpa_user/vduse_dev.c | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index c65f84100e30..ed06c7afd484 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -62,6 +62,7 @@ struct vduse_virtqueue { struct cpumask irq_affinity; spinlock_t irq_affinity_lock; struct kobject kobj; + bool enable_irq_wq; }; struct vduse_dev; @@ -1013,6 +1014,26 @@ static int vduse_dev_queue_irq_work(struct vduse_dev *dev, return ret; } +static int vduse_dev_inject_vq_irq(struct vduse_dev *dev, + struct vduse_virtqueue *vq) +{ + int ret = -EINVAL; + + down_read(&dev->rwsem); + if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK)) + goto unlock; + + ret = 0; + spin_lock_irq(&vq->irq_lock); + if (vq->ready && vq->cb.callback) + vq->cb.callback(vq->cb.private); + spin_unlock_irq(&vq->irq_lock); +unlock: + up_read(&dev->rwsem); + + return ret; +} + static int vduse_dev_dereg_umem(struct vduse_dev *dev, u64 iova, u64 size) { @@ -1278,8 +1299,12 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, break; index = array_index_nospec(index, dev->vq_num); - ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject, + if (dev->vqs[index]->enable_irq_wq) + ret = vduse_dev_queue_irq_work(dev, + &dev->vqs[index]->inject, dev->vqs[index]->irq_effective_cpu); + else + ret = vduse_dev_inject_vq_irq(dev, dev->vqs[index]); break; } case VDUSE_IOTLB_REG_UMEM: { @@ -1420,6 +1445,26 @@ static const struct file_operations vduse_dev_fops = { .llseek = noop_llseek, }; +static ssize_t enable_irq_wq_show(struct vduse_virtqueue *vq, char *buf) +{ + return sprintf(buf, "%d\n", vq->enable_irq_wq); +} + +static ssize_t enable_irq_wq_store(struct vduse_virtqueue *vq, + const char *buf, size_t count) +{ + bool enabled; + int ret; + + ret = kstrtobool(buf, &enabled); + if (ret) + return ret; + + vq->enable_irq_wq = enabled; + + return count; +} + static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) { return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity)); @@ -1480,10 +1525,12 @@ struct vq_sysfs_entry { static struct vq_sysfs_entry irq_cb_affinity_attr = __ATTR_RO(irq_cb_affinity); static struct vq_sysfs_entry irq_cb_effective_affinity_attr = __ATTR_RW(irq_cb_effective_affinity); +static struct vq_sysfs_entry enable_irq_wq_attr = __ATTR_RW(enable_irq_wq); static struct attribute *vq_attrs[] = { &irq_cb_affinity_attr.attr, &irq_cb_effective_affinity_attr.attr, + &enable_irq_wq_attr.attr, NULL, }; ATTRIBUTE_GROUPS(vq); @@ -1565,6 +1612,7 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) dev->vqs[i]->index = i; dev->vqs[i]->irq_effective_cpu = -1; + dev->vqs[i]->enable_irq_wq = true; INIT_WORK(&dev->vqs[i]->inject, vduse_vq_irq_inject); INIT_WORK(&dev->vqs[i]->kick, vduse_vq_kick_work); spin_lock_init(&dev->vqs[i]->kick_lock); From patchwork Mon Dec 5 09:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29614 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2145667wrr; Mon, 5 Dec 2022 01:21:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7H4tRJT+s7YVfe9PtJR0EOWOakoEkoiLs38EhiLt9RdHFEksUFLW3bOFqxtoSVw5nFySWA X-Received: by 2002:a17:902:8d97:b0:189:c056:5c19 with SMTP id v23-20020a1709028d9700b00189c0565c19mr12676908plo.35.1670232102063; Mon, 05 Dec 2022 01:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670232102; cv=none; d=google.com; s=arc-20160816; b=CKv/SG4DQfujoQFOYi/NhjXVTPWTouz7tQJ5OBKX6yYz1vTzAYjJUf+rm2toJcVAxM 4hHQfH2bSDVsySJFLtWTTVakCLwnQvn3lehaxxCys+CUQDGC/al5tXoASDG9vo4iDm4Z 7EkqU/4t4UMw9y2+PZ0aPqBKbFqE7DZuYmfeQM/XcDWKyWEYZj9+IJJbGwfa2ndfMJ4i oyNHDhh10LhO5LMNx+4rgi5bdSwf0dHmYfoPbq1NATlUIdHRrKbvgZOokv9PfX8C0B2S 2OJPgm5KmuZV/lfwbKN9wCgiAlYP4bpuLsBaSJJI6A4lTZLkZVZ5cx19srUBS0t6u58S ZiSQ== 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:date:subject:cc:to:from :dkim-signature; bh=r5ByNntoTnvRrZGf2VdRrzzDsX9jfz3UQsAUMXVoxFo=; b=I1vRQLLueO4bbIzRmXzqGZtgFOXloSQiv7TuAf11WCzWphjcSm9jJyxp+K1HrYA07F AloLiYhqgrSmeNXQT3HqISyIsh2jzt4mr1pyffxhS6P5ZlIS2d0SUghqAWhv4/ptcggD hJ2suHCdLN0wWkcuS/jE31Xs5eKBVmWFJHO73w4cEzRYBrHfIrc0WCCblR8/o5j6pbUu E1vpMZ4F6GoWI/UJ/FfMjt80zAERn+b2hM2SE7Cad8YYCHTKQXOvtzQGzoYDucGMH+L1 NZTViSgr4ys4Kr8c+G/R1lyx5a6gHizMW53CtGB1/fHhgJI+AAvlH71CwAHiDdDTBpS8 /4yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Y64X0WsA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a17090a034700b0021306464b66si13412796pjf.28.2022.12.05.01.21.28; Mon, 05 Dec 2022 01:21:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Y64X0WsA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232524AbiLEJES (ORCPT + 99 others); Mon, 5 Dec 2022 04:04:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbiLEJDa (ORCPT ); Mon, 5 Dec 2022 04:03:30 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 276421055E for ; Mon, 5 Dec 2022 01:03:05 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id jn7so10186277plb.13 for ; Mon, 05 Dec 2022 01:03:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r5ByNntoTnvRrZGf2VdRrzzDsX9jfz3UQsAUMXVoxFo=; b=Y64X0WsAeSkieU6J+IqVSvE0B3KAWXcuKX9mnMKzqJTkrkdg/78DNUN59qfLbkopOo qIYgTfztE6TSf0Qy905iUqYOq99g7R8+iLvx1ZiqE4E3rzmxZIyIeE2c+RXCmpkhT53L C5CGa0hsM9s5S7gtUl6tYNiiaqWT9QBW6+RuJKSGbcpB75H5ANMc+M+zIx+oeXNHDyLx 2CKiX8Xfnr/jVo9IQ+qLCjtzZPKz2R9sMqm8VkE/Dqp+wDCIOchvAFFv8SacHZ6w9b+7 0xLSFrmDeGZ4CaC6WxjzN4nh6BTf1da5SNUHNhs80RCTpwwnOnuNcHRTEengQ6k38kGU IeGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r5ByNntoTnvRrZGf2VdRrzzDsX9jfz3UQsAUMXVoxFo=; b=DzcHMB4TqaYsPSVy0QHduLCJAraR/pefP1+QWe+mLslRFlOZORXVZXe0isN2Te4HnG rme/Se/1Rq1uQ0xNIPzs2oMesO05YoUCZCPiyHpZqXAktmeBprXP+edR9v+fI2rVeCpY svlwB5dYziw21d1GAjnEza3rxBVaPUOK8zBWFAlh6ufK8SwSt5UbgLSG9tVa/LKZ8dhk EonKs5xZ9OLsfZUNzrmpqFHIdkIIlQQn8Lj+EPhgGc1LKZkrI1RPD7u0Hb4wEmQl5Clo J4GvuTuPU0CPL+kOmVR+XKdEddbesCLZtNkinaCzcBzwDF7JcxmQzkmFiVrkjdqnuogK FQtQ== X-Gm-Message-State: ANoB5pnzeBHpAfyseKtHw/2uWEDWns8iqQ9GdQYfW0B2OWh4xeRWeJ9Z wFRdX0SdElewXzotx/4Zgkv8 X-Received: by 2002:a17:90a:a591:b0:219:2926:372a with SMTP id b17-20020a17090aa59100b002192926372amr43048774pjq.110.1670230984614; Mon, 05 Dec 2022 01:03:04 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id r13-20020aa7962d000000b00576d4d69909sm2223087pfg.8.2022.12.05.01.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 01:03:04 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/11] vduse: Delay iova domain creation Date: Mon, 5 Dec 2022 17:02:42 +0800 Message-Id: <20221205090243.791-4-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205090243.791-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> <20221205090243.791-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751365296940186008?= X-GMAIL-MSGID: =?utf-8?q?1751365296940186008?= Delay creating iova domain until the vduse device is binded to vdpa bus. This is a preparation for adding sysfs interface to support specifying bounce buffer size for the iova domain. Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 75 +++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index ed06c7afd484..bd1ba6c33e09 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -112,6 +112,8 @@ struct vduse_dev { u32 vq_align; struct vduse_umem *umem; struct mutex mem_lock; + unsigned int bounce_size; + struct mutex domain_lock; }; struct vduse_dev_msg { @@ -427,7 +429,7 @@ static void vduse_dev_reset(struct vduse_dev *dev) struct vduse_iova_domain *domain = dev->domain; /* The coherent mappings are handled in vduse_dev_free_coherent() */ - if (domain->bounce_map) + if (domain && domain->bounce_map) vduse_domain_reset_bounce_map(domain); down_write(&dev->rwsem); @@ -1045,6 +1047,9 @@ static int vduse_dev_dereg_umem(struct vduse_dev *dev, goto unlock; ret = -EINVAL; + if (!dev->domain) + goto unlock; + if (dev->umem->iova != iova || size != dev->domain->bounce_size) goto unlock; @@ -1071,7 +1076,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, unsigned long npages, lock_limit; int ret; - if (!dev->domain->bounce_map || + if (!dev->domain || !dev->domain->bounce_map || size != dev->domain->bounce_size || iova != 0 || uaddr & ~PAGE_MASK) return -EINVAL; @@ -1145,7 +1150,6 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, struct vduse_iotlb_entry entry; struct vhost_iotlb_map *map; struct vdpa_map_file *map_file; - struct vduse_iova_domain *domain = dev->domain; struct file *f = NULL; ret = -EFAULT; @@ -1156,8 +1160,13 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, if (entry.start > entry.last) break; - spin_lock(&domain->iotlb_lock); - map = vhost_iotlb_itree_first(domain->iotlb, + mutex_lock(&dev->domain_lock); + if (!dev->domain) { + mutex_unlock(&dev->domain_lock); + break; + } + spin_lock(&dev->domain->iotlb_lock); + map = vhost_iotlb_itree_first(dev->domain->iotlb, entry.start, entry.last); if (map) { map_file = (struct vdpa_map_file *)map->opaque; @@ -1167,7 +1176,8 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, entry.last = map->last; entry.perm = map->perm; } - spin_unlock(&domain->iotlb_lock); + spin_unlock(&dev->domain->iotlb_lock); + mutex_unlock(&dev->domain_lock); ret = -EINVAL; if (!f) break; @@ -1319,8 +1329,10 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, sizeof(umem.reserved))) break; + mutex_lock(&dev->domain_lock); ret = vduse_dev_reg_umem(dev, umem.iova, umem.uaddr, umem.size); + mutex_unlock(&dev->domain_lock); break; } case VDUSE_IOTLB_DEREG_UMEM: { @@ -1334,15 +1346,15 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, if (!is_mem_zero((const char *)umem.reserved, sizeof(umem.reserved))) break; - + mutex_lock(&dev->domain_lock); ret = vduse_dev_dereg_umem(dev, umem.iova, umem.size); + mutex_unlock(&dev->domain_lock); break; } case VDUSE_IOTLB_GET_INFO: { struct vduse_iova_info info; struct vhost_iotlb_map *map; - struct vduse_iova_domain *domain = dev->domain; ret = -EFAULT; if (copy_from_user(&info, argp, sizeof(info))) @@ -1356,18 +1368,24 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, sizeof(info.reserved))) break; - spin_lock(&domain->iotlb_lock); - map = vhost_iotlb_itree_first(domain->iotlb, + mutex_lock(&dev->domain_lock); + if (!dev->domain) { + mutex_unlock(&dev->domain_lock); + break; + } + spin_lock(&dev->domain->iotlb_lock); + map = vhost_iotlb_itree_first(dev->domain->iotlb, info.start, info.last); if (map) { info.start = map->start; info.last = map->last; info.capability = 0; - if (domain->bounce_map && map->start == 0 && - map->last == domain->bounce_size - 1) + if (dev->domain->bounce_map && map->start == 0 && + map->last == dev->domain->bounce_size - 1) info.capability |= VDUSE_IOVA_CAP_UMEM; } - spin_unlock(&domain->iotlb_lock); + spin_unlock(&dev->domain->iotlb_lock); + mutex_unlock(&dev->domain_lock); if (!map) break; @@ -1390,7 +1408,10 @@ static int vduse_dev_release(struct inode *inode, struct file *file) { struct vduse_dev *dev = file->private_data; - vduse_dev_dereg_umem(dev, 0, dev->domain->bounce_size); + mutex_lock(&dev->domain_lock); + if (dev->domain) + vduse_dev_dereg_umem(dev, 0, dev->domain->bounce_size); + mutex_unlock(&dev->domain_lock); spin_lock(&dev->msg_lock); /* Make sure the inflight messages can processed after reconncection */ list_splice_init(&dev->recv_list, &dev->send_list); @@ -1647,6 +1668,7 @@ static struct vduse_dev *vduse_dev_create(void) mutex_init(&dev->lock); mutex_init(&dev->mem_lock); + mutex_init(&dev->domain_lock); spin_lock_init(&dev->msg_lock); INIT_LIST_HEAD(&dev->send_list); INIT_LIST_HEAD(&dev->recv_list); @@ -1696,7 +1718,8 @@ static int vduse_destroy_dev(char *name) idr_remove(&vduse_idr, dev->minor); kvfree(dev->config); vduse_dev_deinit_vqs(dev); - vduse_domain_destroy(dev->domain); + if (dev->domain) + vduse_domain_destroy(dev->domain); kfree(dev->name); vduse_dev_destroy(dev); module_put(THIS_MODULE); @@ -1802,11 +1825,7 @@ static int vduse_create_dev(struct vduse_dev_config *config, if (!dev->name) goto err_str; - dev->domain = vduse_domain_create(VDUSE_IOVA_SIZE - 1, - VDUSE_BOUNCE_SIZE); - if (!dev->domain) - goto err_domain; - + dev->bounce_size = VDUSE_BOUNCE_SIZE; dev->config = config_buf; dev->config_size = config->config_size; @@ -1836,8 +1855,6 @@ static int vduse_create_dev(struct vduse_dev_config *config, err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: - vduse_domain_destroy(dev->domain); -err_domain: kfree(dev->name); err_str: vduse_dev_destroy(dev); @@ -2004,9 +2021,23 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, if (ret) return ret; + mutex_lock(&dev->domain_lock); + if (!dev->domain) + dev->domain = vduse_domain_create(VDUSE_IOVA_SIZE - 1, + dev->bounce_size); + mutex_unlock(&dev->domain_lock); + if (!dev->domain) { + put_device(&dev->vdev->vdpa.dev); + return -ENOMEM; + } + ret = _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num); if (ret) { put_device(&dev->vdev->vdpa.dev); + mutex_lock(&dev->domain_lock); + vduse_domain_destroy(dev->domain); + dev->domain = NULL; + mutex_unlock(&dev->domain_lock); return ret; } From patchwork Mon Dec 5 09:02:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 29613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2143642wrr; Mon, 5 Dec 2022 01:15:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7u8pfRAO3le7SbN/4braMQr5Q+gjhzYkmwAdGl3BTrg5Ud6tkTgM20umMYgiLynHdFlft9 X-Received: by 2002:a17:906:f896:b0:7bb:cdd8:94e7 with SMTP id lg22-20020a170906f89600b007bbcdd894e7mr40785194ejb.369.1670231703117; Mon, 05 Dec 2022 01:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670231703; cv=none; d=google.com; s=arc-20160816; b=K07Go5GzAOrgTujLxNYrpyV7JdSLefZUkc/GOXlL7xCJtGKPKCtBWHf1iNJppw2vLB elABoMoSYSMhqt1eUy/kAGQGIAxeX5IPTc1zbbhvz+J+5HGa0Ts7nk7Ef26OXjKvoNwE ZbdArSBq5FzqnQ5vhI9jr5v7Hc20qj62rKUmcB528i984APPzSU9zhl8gJ9M1o+SaLyh C2iePv3ilCypMRZXQrb3Y+vZTHbe4fG0l1ZHu384Eyo4E63RTMfzt2Pbi+cAZ20xIjVL VQ205dmnfqE7r34dLTNig5jCKPRXg8E9qbNcfmliV6AG7LipuPEi6YkLx4WUevAkN3yt wwOw== 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:date:subject:cc:to:from :dkim-signature; bh=XWxGCnE4cMT6K0HQFCyve+aNrYkKjwqaHEJoIAcYwCI=; b=IVjP/fDjC9Qi10jjM/YHFt88Qdqa3tlvR7idg3hEc7j+M6cOaq3uhqpui86pxqjA4u Rnw0hulQj1vm96pzyBqxOwzkmPcSBcK5pGjuABeEQ27XbOYoxGOzo4cYw+pyLIeFUb9o oZG8BM16n7vUUQMnwzfXPKVe9TIfsVqna9Xld/bnDAbAriNdSTwF4S5hANEoxvVvbb39 G8VCL9XKzNaRdetu+cjLgIBBniR3hPP2LoqfEe0gQ3IsYMcinQ1GgvtnlOn6dQPhbaLr sbh/u9GA3fYi51Fm9aQD2BjYF0nomZtvHRAH4kgo8IoNaSAdUlACgweu24UMAr3S4Eif tPKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=HdyukylH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga3-20020a1709070c0300b007c0b56b90f5si8896846ejc.307.2022.12.05.01.14.38; Mon, 05 Dec 2022 01:15:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=HdyukylH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232529AbiLEJEV (ORCPT + 99 others); Mon, 5 Dec 2022 04:04:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232481AbiLEJDb (ORCPT ); Mon, 5 Dec 2022 04:03:31 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F4D10053 for ; Mon, 5 Dec 2022 01:03:08 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id h193so9915188pgc.10 for ; Mon, 05 Dec 2022 01:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XWxGCnE4cMT6K0HQFCyve+aNrYkKjwqaHEJoIAcYwCI=; b=HdyukylHw8JYnlc6L3Z96Hx1GieiRkN71kPt1UPuhOh1caX2gFVznQh/62l/cWUzOD RGUEwc8ODIw5rjeuB/EJif0iBKSn0s/1OcQHcEdLCYZozB2NQMZdV0f1yCN5GvJUsMb5 wO2qaW5zJfVTuPZQMBxw+BBE1VgEjcpV/lm7aKruIZFdHwxMp5MX6s3ZUKVO90yb849u WwwarP9+CdRtF4a3qFjtXYihae1Jyo+Ou7M5ERXlsocx/5E76sDHiK7IcfhGdSo4FSCY y7Huk5OW5PBfnsi540sbwQwCKRYhZYcgInuL22L69S+p9l6Ay4XAwZ18t0csNLdCrg89 ctiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XWxGCnE4cMT6K0HQFCyve+aNrYkKjwqaHEJoIAcYwCI=; b=vIaI+lIOowXf8+s4iIGtgNU759u0eo/FIZBttvtiB5buu4m+q9nwNFieCzuM1utgBK H2ixNcph8x4v8GdrqfmHG3DMf4Ubos33+Ae6pRhQE5cDb2wvtaxBheWsdOZjbFutA/M1 axCoWAL8HYJft71NIMPIn4dh+KnxC708tumRkEnc5skWdigYIA1kKKtefRYKuiiLRzPr 4DvpwSuGtmg0Ecn3GnvRsYEj7BQKtWwAyd4pOx1iJ8Qte/oYxJogaU6wav+PJCtNzDHv mEgbeGRWtV6fthTyGvl3Hht7gZQp/hTks47RDG7u0jvqafWWWLzuGBth94M5jniLr3Nj muiA== X-Gm-Message-State: ANoB5pnzaVDi4YAmklxpzJmYOWGr7eFLReILFWId8gFkBR7TmsCzStDv 6QPisYAfwAtAmkbIuS0Xcc5g X-Received: by 2002:a05:6a00:2483:b0:56c:12c0:aaf1 with SMTP id c3-20020a056a00248300b0056c12c0aaf1mr65048213pfv.50.1670230987635; Mon, 05 Dec 2022 01:03:07 -0800 (PST) Received: from localhost ([101.229.232.206]) by smtp.gmail.com with ESMTPSA id p128-20020a62d086000000b00574db8ca00fsm2152429pfg.185.2022.12.05.01.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 01:03:07 -0800 (PST) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, tglx@linutronix.de, hch@lst.de Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/11] vduse: Support specifying bounce buffer size via sysfs Date: Mon, 5 Dec 2022 17:02:43 +0800 Message-Id: <20221205090243.791-5-xieyongji@bytedance.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205090243.791-1-xieyongji@bytedance.com> References: <20221205084127.535-1-xieyongji@bytedance.com> <20221205090243.791-1-xieyongji@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751364878771628907?= X-GMAIL-MSGID: =?utf-8?q?1751364878771628907?= As discussed in [1], this adds sysfs interface to support specifying bounce buffer size in virtio-vdpa case. It would be a performance tuning parameter for high throughput workloads. [1] https://www.spinics.net/lists/netdev/msg754288.html Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 45 +++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index bd1ba6c33e09..0458d61cee1f 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -38,8 +38,11 @@ #define DRV_LICENSE "GPL v2" #define VDUSE_DEV_MAX (1U << MINORBITS) +#define VDUSE_MAX_BOUNCE_SIZE (1024 * 1024 * 1024) +#define VDUSE_MIN_BOUNCE_SIZE (1024 * 1024) #define VDUSE_BOUNCE_SIZE (64 * 1024 * 1024) -#define VDUSE_IOVA_SIZE (128 * 1024 * 1024) +/* 128 MB reserved for virtqueue creation */ +#define VDUSE_IOVA_SIZE (VDUSE_MAX_BOUNCE_SIZE + 128 * 1024 * 1024) #define VDUSE_MSG_DEFAULT_TIMEOUT 30 struct vduse_virtqueue { @@ -1795,8 +1798,48 @@ static ssize_t msg_timeout_store(struct device *device, static DEVICE_ATTR_RW(msg_timeout); +static ssize_t bounce_size_show(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct vduse_dev *dev = dev_get_drvdata(device); + + return sysfs_emit(buf, "%u\n", dev->bounce_size); +} + +static ssize_t bounce_size_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct vduse_dev *dev = dev_get_drvdata(device); + unsigned int bounce_size; + int ret; + + ret = -EPERM; + mutex_lock(&dev->domain_lock); + if (dev->domain) + goto unlock; + + ret = kstrtouint(buf, 10, &bounce_size); + if (ret < 0) + goto unlock; + + ret = -EINVAL; + if (bounce_size > VDUSE_MAX_BOUNCE_SIZE || + bounce_size < VDUSE_MIN_BOUNCE_SIZE) + goto unlock; + + dev->bounce_size = bounce_size & PAGE_MASK; + ret = count; +unlock: + mutex_unlock(&dev->domain_lock); + return ret; +} + +static DEVICE_ATTR_RW(bounce_size); + static struct attribute *vduse_dev_attrs[] = { &dev_attr_msg_timeout.attr, + &dev_attr_bounce_size.attr, NULL };