Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1962918imm; Thu, 24 May 2018 03:40:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqafPEHbWjMW/9r7gOhATiU6zpLupZ8ewp3m5N+14nlE+aBL07qshm8KUCrff75NEHkdxMM X-Received: by 2002:a62:de02:: with SMTP id h2-v6mr6684727pfg.205.1527158427761; Thu, 24 May 2018 03:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158427; cv=none; d=google.com; s=arc-20160816; b=GWFs9Kdr3ERVtzfgCfP7+XyL+q/5JDFHFeD5JvjvkvYW+CkW/8kYQVnmz7EbsFKgpY Z4HikH+70ZfAoX7g1I58efAdp1RZXwE2KPyy6WC08OVykYbtjCe17IQbYsri4rhWHNB0 uUaBS8jnEyjeaX5ILlru55Gi5YF2cwMPxRr8flQsbU1ojKj2TinLab1B7asK6DU5Hl3G IvM7M9/V6puTvyq9uH3wbiN0Hizk1LfARNchIzt7HcCoEKZAYdy+tmLM8SE/zACTqFEt sAo1qKODdiiKtK+PxBGyGvy4qzkMDpeuugrFjTpTp9ONtA1rkHKSv0kf9q/a+Q4AkU92 7K5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=tACKGZiLBFbr/ZkDRKUQ0snsTvxVTjsjYuBBJqAolwE=; b=QdBMMDvdwL3xW0f1kq6JBE9EOiyNDDek9Q9y5pedzSSg6a26CwIzpuVmlnsVUZJ52X hXRYbjEEGJRIHH0rWYc3BOUjqkP1xekCv0xXFHB2Kgda5EM9ubO1aXAND3vUcT1+g2S3 xroeRbo+DSx4QsAMUNV5xfPscJHHOqxL1XDDyyrXIt8P6WtG20pyatG1sYG+hPWVw0C2 66/SP6saOPOEow5gn1vfnXbDUpdmjaFqOJqc/UBElseDuc0e64Yms53grzgJvOBzWHd7 xHOM9FP74nOOlsxa0rw+5weNnXMRhnAh4wLVciJ4pWB6+HVxMLdDpynfHQpm8885IbKa Jsvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IpwkT3Lb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z21-v6si6178417pgn.498.2018.05.24.03.40.12; Thu, 24 May 2018 03:40:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IpwkT3Lb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032237AbeEXKjW (ORCPT + 99 others); Thu, 24 May 2018 06:39:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:40120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030419AbeEXJ7S (ORCPT ); Thu, 24 May 2018 05:59:18 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2894420895; Thu, 24 May 2018 09:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155957; bh=D+Eze+o+niyp3t/fA+FSrsUHKAxc6ppMbTegvzuS+uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpwkT3LbgxczxZJDePTRWiuzOIkTVurocvZIiUsfFHwEUctpPiCV7G98btbfbdOl2 rHrFGsHYoZEcASrFf86mjMU3kZbjnQ+K+n5bumO3W4kZPV7cj4wxcj9hLTjaCamXBm zMGlS5UTzBT6QdpKiIAENXUOHdeZhOEdgruo6Qj0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kumar Sanghvi , Ganesh Goudar , "David S. Miller" Subject: [PATCH 4.16 013/161] cxgb4: Correct ntuple mask validation for hash filters Date: Thu, 24 May 2018 11:37:18 +0200 Message-Id: <20180524093019.992334089@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kumar Sanghvi [ Upstream commit 849a742c59a3d597473c0232f9c2506c69eeef14 ] Earlier code of doing bitwise AND with field width bits was wrong. Instead, simplify code to calculate ntuple_mask based on supplied fields and then compare with mask configured in hw - which is the correct and simpler way to validate ntuple mask. Fixes: 3eb8b62d5a26 ("cxgb4: add support to create hash-filters via tc-flower offload") Signed-off-by: Kumar Sanghvi Signed-off-by: Ganesh Goudar Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 88 +++++++--------------- 1 file changed, 30 insertions(+), 58 deletions(-) --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c @@ -836,7 +836,7 @@ bool is_filter_exact_match(struct adapte { struct tp_params *tp = &adap->params.tp; u64 hash_filter_mask = tp->hash_filter_mask; - u32 mask; + u64 ntuple_mask = 0; if (!is_hashfilter(adap)) return false; @@ -865,73 +865,45 @@ bool is_filter_exact_match(struct adapte if (!fs->val.fport || fs->mask.fport != 0xffff) return false; - if (tp->fcoe_shift >= 0) { - mask = (hash_filter_mask >> tp->fcoe_shift) & FT_FCOE_W; - if (mask && !fs->mask.fcoe) - return false; - } + /* calculate tuple mask and compare with mask configured in hw */ + if (tp->fcoe_shift >= 0) + ntuple_mask |= (u64)fs->mask.fcoe << tp->fcoe_shift; - if (tp->port_shift >= 0) { - mask = (hash_filter_mask >> tp->port_shift) & FT_PORT_W; - if (mask && !fs->mask.iport) - return false; - } + if (tp->port_shift >= 0) + ntuple_mask |= (u64)fs->mask.iport << tp->port_shift; if (tp->vnic_shift >= 0) { - mask = (hash_filter_mask >> tp->vnic_shift) & FT_VNIC_ID_W; - - if ((adap->params.tp.ingress_config & VNIC_F)) { - if (mask && !fs->mask.pfvf_vld) - return false; - } else { - if (mask && !fs->mask.ovlan_vld) - return false; - } + if ((adap->params.tp.ingress_config & VNIC_F)) + ntuple_mask |= (u64)fs->mask.pfvf_vld << tp->vnic_shift; + else + ntuple_mask |= (u64)fs->mask.ovlan_vld << + tp->vnic_shift; } - if (tp->vlan_shift >= 0) { - mask = (hash_filter_mask >> tp->vlan_shift) & FT_VLAN_W; - if (mask && !fs->mask.ivlan) - return false; - } + if (tp->vlan_shift >= 0) + ntuple_mask |= (u64)fs->mask.ivlan << tp->vlan_shift; - if (tp->tos_shift >= 0) { - mask = (hash_filter_mask >> tp->tos_shift) & FT_TOS_W; - if (mask && !fs->mask.tos) - return false; - } + if (tp->tos_shift >= 0) + ntuple_mask |= (u64)fs->mask.tos << tp->tos_shift; - if (tp->protocol_shift >= 0) { - mask = (hash_filter_mask >> tp->protocol_shift) & FT_PROTOCOL_W; - if (mask && !fs->mask.proto) - return false; - } + if (tp->protocol_shift >= 0) + ntuple_mask |= (u64)fs->mask.proto << tp->protocol_shift; - if (tp->ethertype_shift >= 0) { - mask = (hash_filter_mask >> tp->ethertype_shift) & - FT_ETHERTYPE_W; - if (mask && !fs->mask.ethtype) - return false; - } + if (tp->ethertype_shift >= 0) + ntuple_mask |= (u64)fs->mask.ethtype << tp->ethertype_shift; - if (tp->macmatch_shift >= 0) { - mask = (hash_filter_mask >> tp->macmatch_shift) & FT_MACMATCH_W; - if (mask && !fs->mask.macidx) - return false; - } + if (tp->macmatch_shift >= 0) + ntuple_mask |= (u64)fs->mask.macidx << tp->macmatch_shift; + + if (tp->matchtype_shift >= 0) + ntuple_mask |= (u64)fs->mask.matchtype << tp->matchtype_shift; + + if (tp->frag_shift >= 0) + ntuple_mask |= (u64)fs->mask.frag << tp->frag_shift; + + if (ntuple_mask != hash_filter_mask) + return false; - if (tp->matchtype_shift >= 0) { - mask = (hash_filter_mask >> tp->matchtype_shift) & - FT_MPSHITTYPE_W; - if (mask && !fs->mask.matchtype) - return false; - } - if (tp->frag_shift >= 0) { - mask = (hash_filter_mask >> tp->frag_shift) & - FT_FRAGMENTATION_W; - if (mask && !fs->mask.frag) - return false; - } return true; }