Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4418101rwi; Mon, 17 Oct 2022 06:07:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MnCKBwx2fWtgNjS3+q+1WhpK2KhwNOWxKbO4t+g1uInRmy+/17n5fV4GtfUAjAKSpEybM X-Received: by 2002:a05:6a00:16c8:b0:53b:3b9f:7283 with SMTP id l8-20020a056a0016c800b0053b3b9f7283mr12546470pfc.46.1666012031120; Mon, 17 Oct 2022 06:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666012031; cv=none; d=google.com; s=arc-20160816; b=yHKMksSHRSJfxuo8/2osYYQ0p4yW9yBMQP/QlfDNnOnSEbBq2NeZJoouUI9gvJ/wX9 afPtYWhM9kFjcdhnxVrugqRFKwuW3zdMY90vo8X/cQnY2EEbkYc/NRDPAr9o4traWoWo XknZLJm00HxmlgBjMGhZAd56BVITX0n5jZtXMVNdCnXsfAtcZYNB+0RS0atoelcfTcxE Ofsm5xzMkwfy+zUB2FlsdH19d6kbDUC/MrKZVpD93lZkWT5sihU4kTFA8qdUL1LT9zwS qTvS/iburxJ4faDRsFZfLRci35wZ7e62mceKW40PdyB3zmn2orJyEMLnBbIF8Cm0MEs8 pFCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=6rsyyKbthbOrRHQKB4B3EnVvmKjQ4zwm1tq6orvAu9k=; b=egDEYN4yANCt08q4WWfXgMLQvjB1vdqQRGws3yLUgaOz6Udj8dEw1zQGZgdm4ZHtmB wQG4MU+1zSrtl1vt0Z8tFlxIVwc6EKvto29w9tJ1IS9wrTYEL5WM6lgpgtYLgf19Vb7E BkvSJf35WLALA9sF9UrE6KW13Iom/VY8WvcAqOmBRwVEkiabBuH9Gz4v4p0V8TrPGoo9 Wbee0KhlXLt0QeoLJUXC9X1SF/syxsHcNL5qkNr/KGlnjfzU5SB6LxEs8py25y2V5f9J /SP/2NSedXWHZ5WIDYrS9oYhvRusXHW5RXX+s0XFYaJcer8beHAuJkYoDhzLkH3HOKv3 cX6w== ARC-Authentication-Results: i=1; mx.google.com; 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=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a170902c94a00b0016d2e8c2233si14346346pla.333.2022.10.17.06.06.50; Mon, 17 Oct 2022 06:07:11 -0700 (PDT) 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; 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=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbiJQM6i convert rfc822-to-8bit (ORCPT + 99 others); Mon, 17 Oct 2022 08:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbiJQM6c (ORCPT ); Mon, 17 Oct 2022 08:58:32 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C937C31EC0 for ; Mon, 17 Oct 2022 05:58:31 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-314-T0677u4MObuNSCaKuUVJww-1; Mon, 17 Oct 2022 13:58:27 +0100 X-MC-Unique: T0677u4MObuNSCaKuUVJww-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 17 Oct 2022 13:58:25 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.042; Mon, 17 Oct 2022 13:58:25 +0100 From: David Laight To: 'Huacai Chen' , Huacai Chen CC: "loongarch@lists.linux.dev" , Xuefeng Li , Tiezhu Yang , Guo Ren , Xuerui Wang , Jiaxun Yang , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH V2] LoongArch: Add unaligned access support Thread-Topic: [PATCH V2] LoongArch: Add unaligned access support Thread-Index: AQHY4c+4g3BwiNKgXk2nk+NWr+NpZK4SijAg Date: Mon, 17 Oct 2022 12:58:25 +0000 Message-ID: References: <20221017022330.2383060-1-chenhuacai@loongson.cn> In-Reply-To: <20221017022330.2383060-1-chenhuacai@loongson.cn> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 From: Huacai Chen > Sent: 17 October 2022 03:24 > > Loongson-2 series (Loongson-2K500, Loongson-2K1000) don't support > unaligned access in hardware, while Loongson-3 series (Loongson-3A5000, > Loongson-3C5000) are configurable whether support unaligned access in > hardware. This patch add unaligned access emulation for those LoongArch > processors without hardware support. > ... > + /* > + * This load never faults. > + */ > + __get_inst(&insn.word, pc, user); On what basis does it never fault? Any user access can fault. If nothing else another thread of the process can unmap the page. > + if (user && !access_ok(addr, 8)) > + goto sigbus; Surely that is technically wrong - a two or four byte access is valid right at the end of valid user addreeses. > + > + if (insn.reg2i12_format.opcode == ldd_op || > + insn.reg2i14_format.opcode == ldptrd_op || > + insn.reg3_format.opcode == ldxd_op) { > + res = unaligned_read(addr, &value, 8, 1); That is the most horrid indentation of long lines I've ever seen. I'd also guess you can common up some of this code by looking at the instruction field that include the transfer width. The long elsif list will generate horrid code. But maybe since you've just taken a fault it really doesn't matter. Indeed just emulating in C using byte accesses it probably fine. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)