From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC8E22FFDED for ; Tue, 2 Dec 2025 07:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764661291; cv=none; b=CmtU4bRsRxcID+Sg5s5VfwSPde5Bdsbm9dDC7YlbR6//xQjrDF6JI+LQ9B1oMrnkspJbA3m1VF6WX22e0fV+fWgqjjloiC5iIal0cG/7yojntCDds9cSk7lMNZSYxQvfp7DA9KfHpGrNtFDuGk2DrLm87YkBijY/tBaiTqZzZCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764661291; c=relaxed/simple; bh=x1lj4DNyycP+lgT8cRxQ1Y4CVJ4e8I0kS7WojS+6v10=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=aXPKezPIrnC5OI7yqlPsm+LQxdjlcDN0KT9+5FRPqiln8pKIYF5RISAn0k28XwrLRDJEJ2d8O9eOOqJx0q4Fbd87uEaDDVdyJf+7CT0oj3TYtX3f9MwpQL59igo219+ilGn66pDrHCnB3oRrYM2dzS4X4hA+xQkXPl8jLZdkiiM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y+JOHsgM; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y+JOHsgM" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2957850c63bso38019825ad.0 for ; Mon, 01 Dec 2025 23:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764661289; x=1765266089; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=w2q6telcg/QsshlBLoOse/YPsUmfsRR7i8AupYK9gqY=; b=Y+JOHsgMAf7a8g0RZp3StjvqyBB9ojcYsDl5BD/ROwMaWmsvZAa/1BDecvg7X18ssL 2wzPAKXVqFeKsgVdHd2COxVIy6m7qOK5PvO9IHYxynh20zhndvGRW/hoIl6IEb5hjrMr /zLagw+P2ktW7utZh8w+s8GlL+3dhiUobWbHI1+ABSREl79PvvRNlXC3mTzEZLQJ/GNo ewUCq7WcW4FafVlfZOdLMNEVGyj+GaSs4+tNg4Z0gUYC2lGrd9luzJOenBcvIOqLciBC 8qon4WNvna0nF63CFYguflz2bvMKvbXmw9hB5VoaENqLyxT8g393yzZPA/71lM8qxeyi Punw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764661289; x=1765266089; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=w2q6telcg/QsshlBLoOse/YPsUmfsRR7i8AupYK9gqY=; b=aE6KbFS98XsGVbu95PdcJn1I7hHWQjbZb3U9FAaL3q2uZo4gxo2Gal7ttZCXJvy5H9 iJq1Gol2n2XwZMMAXxyJojy2e26Z78mM+PoFLP/UKBJp1kIwFbb0aiiBuLZE9ldHz5wi wM4IjgWKJtO4NfCmbf9q5wFEf4tsKehts5iTayjXz6LU8Ip4fh3AOzZbg3NZ2CsugNrf 0Dh0vcBjPJLtVdn3X4aaL3JlinEuYdbIua6IaXTwYV9kfmDMVJxY5wv569o9ypC3ozPG PizqDpSNdNdR3Ke9TCeUBNQpeyulAcWKbodi2yobSjZQ/D4gQoTFPqr0frRsaaqtkEhd mBog== X-Forwarded-Encrypted: i=1; AJvYcCXiWd2/Zz+BVecyGlw3UZYJhDWZzx3GeQpBtCyhkkArfwfteHaKCkRqPSq3ycc0IXKEXzFlbF+ZBxdd0CU=@vger.kernel.org X-Gm-Message-State: AOJu0YydFGcn8PawYqVYy0MXdi7MAVFYyiZmAjmMsBNHYnMa87GgrsFY tGeHUOzYWTC91U3Oja1sxDd+ybzJvUO9VT7rHDrcNXjYoBQ+sfHuqIau8YFYdw== X-Gm-Gg: ASbGncvfFgN6Pq4CW3oCmCX4HY7PTuo4spXz6ej6Vt9lMdtxeR5UcMIYmSlZ4evhQI9 B2vv3EOb8Rv5jLC2Iz3sBsXFDhR+t3KsUR74RSMIm+ng0XSFTkRTMx6AnENwKrw3IADB3cZtoRf foW7dH652chg3nFm9ycEZ3tWIvyHSRVuQEnoYcR4DwuEs+0qIN48jTXsPxGm/3Fk/vpZS7CpOjl 02+OWBN3NPXAaPh4/peG14aHAq069e89cBE+GFfZiAn+5J/138FfgK9IdEdpz0h4tD0Y1t6ebyB t5rcYO5sWyryGD0iFCWZQReH8ffP1FFi0P7zgwQhiYH/2p7KqKtgvuOH/ZJ9gr0Twwvc5NbCwQr U/ADuDtpZ7H05gxMMCct+hJzoD8lC2KsdPvnP6IiD3fg7PzmxXj/0kx4X1iud+Zwf9YsIBQBXbw xbtn1Y9hfnAC9+G6qTaesTCT90awHkI0gM+Vm0OqlcZOh5 X-Google-Smtp-Source: AGHT+IFznH971tY4p3rpMndCd98S3a5M91d+eC9g7o4pmW7WaT8RC+BcW6tVEoSAhAE25ttCWo2c0w== X-Received: by 2002:a17:902:e950:b0:295:28a4:f0c6 with SMTP id d9443c01a7336-29d5a359bd8mr20672965ad.0.1764661289223; Mon, 01 Dec 2025 23:41:29 -0800 (PST) Received: from mao-OptiPlex-3050.hz.ali.com ([47.246.101.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bceb7f69asm142957605ad.102.2025.12.01.23.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 23:41:28 -0800 (PST) From: maohan4761@gmail.com To: pjw@kernel.org, palmer@dabbelt.com Cc: guoren@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Mao Han Subject: [PATCH 0/1] riscv: Optimize user copy with efficient unaligned access support Date: Tue, 2 Dec 2025 15:41:20 +0800 Message-Id: <20251202074121.81364-1-maohan4761@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Mao Han Many modern high-performance processors now handle unaligned memory accesses with performance nearly on par with aligned accesses. However, the current kernel implementation of fallback_scalar_usercopy_sum_enabled still defaults to aligning accesses to register size boundaries. This path incurs additional shift-and-combine operations that fail to fully leverage hardware capabilities and cannot utilize wide-load/store instructions for trailing data chunks smaller than 9 × SZREG. This patch introduces an optimized code path enabled by RISCV_EFFICIENT_UNALIGNED_ACCESS, which relies on hardware support for efficient unaligned memory accesses. By doing so, the software can fully exploit the maximum available load/store instruction width and avoids complex bit-manipulation logic for reassembly. The optimization significantly improves performance of __asm_copy_to/from_user for transfers smaller than riscv_v_usercopy_threshold. In particular, for small data sizes (8–72 bytes) under unaligned scenarios, performance gains range from 40% to 600%. lmbench’s sig hndl/catch test shows approximately a 20% improvement, and iperf small-packet throughput sees noticeable gains as well. Mao Han (1): riscv: Optimize user copy with efficient unaligned access support arch/riscv/lib/uaccess.S | 113 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) -- 2.25.1