From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AFE7C2BA19 for ; Wed, 15 Apr 2020 08:30:27 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6DBF320768 for ; Wed, 15 Apr 2020 08:30:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DBF320768 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 32F5A86E68; Wed, 15 Apr 2020 08:30:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Iwpo+iIFHJMd; Wed, 15 Apr 2020 08:30:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 5954B86E41; Wed, 15 Apr 2020 08:30:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 42322C1AE2; Wed, 15 Apr 2020 08:30:26 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 640A6C0172 for ; Wed, 15 Apr 2020 08:30:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2BF3620384 for ; Wed, 15 Apr 2020 08:30:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W3aarbt8VAaw for ; Wed, 15 Apr 2020 08:30:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by silver.osuosl.org (Postfix) with ESMTPS id 5D65720020 for ; Wed, 15 Apr 2020 08:30:24 +0000 (UTC) IronPort-SDR: Av1v7+vZde8Ci6PA3kWlg5UAhqkr/OHBthFf+/61RExM8AQrQZtgzoQgL9cUAWZ1h/7VarnlIx CDxkX4PX21RA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2020 01:30:23 -0700 IronPort-SDR: CjquGXrasSwTCvhBudoPJmdL6OaKLWC9jlj9FTOATiHLjGGp7TfNIZlkEqeVZdKjQzIGXaM+7G Hwp+t6iz4Tbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,386,1580803200"; d="scan'208";a="363612788" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.210.208]) ([10.254.210.208]) by fmsmga001.fm.intel.com with ESMTP; 15 Apr 2020 01:30:21 -0700 Subject: Re: [PATCH v2 2/7] iommu/vt-d: Multiple descriptors per qi_submit_sync() To: "Tian, Kevin" , Joerg Roedel References: <20200415052542.30421-1-baolu.lu@linux.intel.com> <20200415052542.30421-3-baolu.lu@linux.intel.com> From: Lu Baolu Message-ID: <85ee7356-dd36-e872-8196-ad44bbc1ad20@linux.intel.com> Date: Wed, 15 Apr 2020 16:30:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Cc: "Raj, Ashok" , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On 2020/4/15 16:18, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Wednesday, April 15, 2020 1:26 PM >> >> Extend qi_submit_sync() function to support multiple descriptors. >> >> Signed-off-by: Jacob Pan >> Signed-off-by: Lu Baolu >> --- >> drivers/iommu/dmar.c | 39 +++++++++++++++++++++++-------------- >> include/linux/intel-iommu.h | 1 + >> 2 files changed, 25 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c >> index bb42177e2369..61d049e91f84 100644 >> --- a/drivers/iommu/dmar.c >> +++ b/drivers/iommu/dmar.c >> @@ -1157,12 +1157,11 @@ static inline void reclaim_free_desc(struct >> q_inval *qi) >> } >> } >> >> -static int qi_check_fault(struct intel_iommu *iommu, int index) >> +static int qi_check_fault(struct intel_iommu *iommu, int index, int >> wait_index) >> { >> u32 fault; >> int head, tail; >> struct q_inval *qi = iommu->qi; >> - int wait_index = (index + 1) % QI_LENGTH; >> int shift = qi_shift(iommu); >> >> if (qi->desc_status[wait_index] == QI_ABORT) >> @@ -1234,12 +1233,12 @@ static int qi_check_fault(struct intel_iommu >> *iommu, int index) >> int qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc, >> unsigned int count, unsigned long options) >> { >> - int rc; >> struct q_inval *qi = iommu->qi; >> - int offset, shift, length; >> struct qi_desc wait_desc; >> int wait_index, index; >> unsigned long flags; >> + int offset, shift; >> + int rc, i; >> >> if (!qi) >> return 0; >> @@ -1248,32 +1247,41 @@ int qi_submit_sync(struct intel_iommu *iommu, >> struct qi_desc *desc, >> rc = 0; >> >> raw_spin_lock_irqsave(&qi->q_lock, flags); >> - while (qi->free_cnt < 3) { >> + /* >> + * Check if we have enough empty slots in the queue to submit, >> + * the calculation is based on: >> + * # of desc + 1 wait desc + 1 space between head and tail >> + */ >> + while (qi->free_cnt < count + 2) { >> raw_spin_unlock_irqrestore(&qi->q_lock, flags); >> cpu_relax(); >> raw_spin_lock_irqsave(&qi->q_lock, flags); >> } >> >> index = qi->free_head; >> - wait_index = (index + 1) % QI_LENGTH; >> + wait_index = (index + count) % QI_LENGTH; >> shift = qi_shift(iommu); >> - length = 1 << shift; >> >> - qi->desc_status[index] = qi->desc_status[wait_index] = QI_IN_USE; >> + for (i = 0; i < count; i++) { >> + offset = ((index + i) % QI_LENGTH) << shift; >> + memcpy(qi->desc + offset, &desc[i], 1 << shift); >> + qi->desc_status[(index + i) % QI_LENGTH] = QI_IN_USE; >> + } > what about doing one memcpy and leave the loop only for updating > qi status? > One memcpy might cross the table boundary. Best regards, baolu _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1582C2BA19 for ; Wed, 15 Apr 2020 08:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7C5020784 for ; Wed, 15 Apr 2020 08:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2894606AbgDOIak (ORCPT ); Wed, 15 Apr 2020 04:30:40 -0400 Received: from mga01.intel.com ([192.55.52.88]:20237 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408049AbgDOIaY (ORCPT ); Wed, 15 Apr 2020 04:30:24 -0400 IronPort-SDR: Q83+BV94Vsja4E3ftE9q/OsR698zYpMy5n45PMbXPrpuTwiMOJbQnFX0CAxFKdxt4mZ4gQAy8+ k1ETePawBbtA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2020 01:30:23 -0700 IronPort-SDR: CjquGXrasSwTCvhBudoPJmdL6OaKLWC9jlj9FTOATiHLjGGp7TfNIZlkEqeVZdKjQzIGXaM+7G Hwp+t6iz4Tbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,386,1580803200"; d="scan'208";a="363612788" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.210.208]) ([10.254.210.208]) by fmsmga001.fm.intel.com with ESMTP; 15 Apr 2020 01:30:21 -0700 Cc: baolu.lu@linux.intel.com, "Raj, Ashok" , "jacob.jun.pan@linux.intel.com" , "Liu, Yi L" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 2/7] iommu/vt-d: Multiple descriptors per qi_submit_sync() To: "Tian, Kevin" , Joerg Roedel References: <20200415052542.30421-1-baolu.lu@linux.intel.com> <20200415052542.30421-3-baolu.lu@linux.intel.com> From: Lu Baolu Message-ID: <85ee7356-dd36-e872-8196-ad44bbc1ad20@linux.intel.com> Date: Wed, 15 Apr 2020 16:30:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/4/15 16:18, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Wednesday, April 15, 2020 1:26 PM >> >> Extend qi_submit_sync() function to support multiple descriptors. >> >> Signed-off-by: Jacob Pan >> Signed-off-by: Lu Baolu >> --- >> drivers/iommu/dmar.c | 39 +++++++++++++++++++++++-------------- >> include/linux/intel-iommu.h | 1 + >> 2 files changed, 25 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c >> index bb42177e2369..61d049e91f84 100644 >> --- a/drivers/iommu/dmar.c >> +++ b/drivers/iommu/dmar.c >> @@ -1157,12 +1157,11 @@ static inline void reclaim_free_desc(struct >> q_inval *qi) >> } >> } >> >> -static int qi_check_fault(struct intel_iommu *iommu, int index) >> +static int qi_check_fault(struct intel_iommu *iommu, int index, int >> wait_index) >> { >> u32 fault; >> int head, tail; >> struct q_inval *qi = iommu->qi; >> - int wait_index = (index + 1) % QI_LENGTH; >> int shift = qi_shift(iommu); >> >> if (qi->desc_status[wait_index] == QI_ABORT) >> @@ -1234,12 +1233,12 @@ static int qi_check_fault(struct intel_iommu >> *iommu, int index) >> int qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc, >> unsigned int count, unsigned long options) >> { >> - int rc; >> struct q_inval *qi = iommu->qi; >> - int offset, shift, length; >> struct qi_desc wait_desc; >> int wait_index, index; >> unsigned long flags; >> + int offset, shift; >> + int rc, i; >> >> if (!qi) >> return 0; >> @@ -1248,32 +1247,41 @@ int qi_submit_sync(struct intel_iommu *iommu, >> struct qi_desc *desc, >> rc = 0; >> >> raw_spin_lock_irqsave(&qi->q_lock, flags); >> - while (qi->free_cnt < 3) { >> + /* >> + * Check if we have enough empty slots in the queue to submit, >> + * the calculation is based on: >> + * # of desc + 1 wait desc + 1 space between head and tail >> + */ >> + while (qi->free_cnt < count + 2) { >> raw_spin_unlock_irqrestore(&qi->q_lock, flags); >> cpu_relax(); >> raw_spin_lock_irqsave(&qi->q_lock, flags); >> } >> >> index = qi->free_head; >> - wait_index = (index + 1) % QI_LENGTH; >> + wait_index = (index + count) % QI_LENGTH; >> shift = qi_shift(iommu); >> - length = 1 << shift; >> >> - qi->desc_status[index] = qi->desc_status[wait_index] = QI_IN_USE; >> + for (i = 0; i < count; i++) { >> + offset = ((index + i) % QI_LENGTH) << shift; >> + memcpy(qi->desc + offset, &desc[i], 1 << shift); >> + qi->desc_status[(index + i) % QI_LENGTH] = QI_IN_USE; >> + } > what about doing one memcpy and leave the loop only for updating > qi status? > One memcpy might cross the table boundary. Best regards, baolu