From patchwork Fri Mar 29 07:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 13610226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB02CCD128E for ; Fri, 29 Mar 2024 07:12:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rq6Og-0007GR-En; Fri, 29 Mar 2024 03:11:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rq6Oc-0007FU-13 for qemu-devel@nongnu.org; Fri, 29 Mar 2024 03:11:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rq6OY-0001AK-VF for qemu-devel@nongnu.org; Fri, 29 Mar 2024 03:11:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711696281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1WyJLX8ea9OjJ6HHxYKsQuwbKPPt4phmo4Lf1pOTsRA=; b=O7qE6tcfEcd8Tn/GuAsSn0xo4IZ2jvk3R75mnnhQJAeFwnZLxgB3xaP2ca17/v3i854VtY 70HZyLVUaak89zWuaT2HI4/nkTqtdQVMcIgMdAjfakmIOUFxruSdktG/yoFBAcSRE0Kjsn mwT7nTszBf4YgJ63mW0jzeY6zNp4xN4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-601-OAP52hVTMg2hd6dpAgVeFQ-1; Fri, 29 Mar 2024 03:11:17 -0400 X-MC-Unique: OAP52hVTMg2hd6dpAgVeFQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD4DB8007A1; Fri, 29 Mar 2024 07:11:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id A21ABC423E0; Fri, 29 Mar 2024 07:11:14 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Akihiko Odaki , Andrew Melnychenko , Jason Wang Subject: [PULL 2/5] ebpf: Fix indirections table setting Date: Fri, 29 Mar 2024 15:10:57 +0800 Message-ID: <20240329071100.31376-3-jasowang@redhat.com> In-Reply-To: <20240329071100.31376-1-jasowang@redhat.com> References: <20240329071100.31376-1-jasowang@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.08, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki The kernel documentation says: > The value stored can be of any size, however, all array elements are > aligned to 8 bytes. https://www.kernel.org/doc/html/v6.8/bpf/map_array.html Fixes: 333b3e5fab75 ("ebpf: Added eBPF map update through mmap.") Signed-off-by: Akihiko Odaki Acked-by: Andrew Melnychenko Signed-off-by: Jason Wang --- ebpf/ebpf_rss.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c index 2e506f9743..d102f3dd09 100644 --- a/ebpf/ebpf_rss.c +++ b/ebpf/ebpf_rss.c @@ -185,13 +185,18 @@ static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx, uint16_t *indirections_table, size_t len) { + char *cursor = ctx->mmap_indirections_table; + if (!ebpf_rss_is_loaded(ctx) || indirections_table == NULL || len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { return false; } - memcpy(ctx->mmap_indirections_table, indirections_table, - sizeof(*indirections_table) * len); + for (size_t i = 0; i < len; i++) { + *(uint16_t *)cursor = indirections_table[i]; + cursor += 8; + } + return true; }