mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hengqi Chen <chenhengqi@outlook.com>
To: Tiezhu Yang <yangtiezhu@loongson.cn>,
	Huacai Chen <chenhuacai@kernel.org>,
	WANG Xuerui <kernel@xen0n.name>
Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
	loongson-kernel@lists.loongnix.cn
Subject: Re: [PATCH v2 0/4] Add uprobes support for LoongArch
Date: Mon, 17 Apr 2023 11:17:55 +0800	[thread overview]
Message-ID: <SY4P282MB351877A70A0333C790FE85A5C09C9@SY4P282MB3518.AUSP282.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <1681464781-4428-1-git-send-email-yangtiezhu@loongson.cn>

Hi Tiezhu:

On 2023/4/14 17:32, Tiezhu Yang wrote:
> v2:
>   -- Move the functions to inst.c in patch #1
>   -- Pass around union for insns_not_supported(),
>      insns_need_simulation() and arch_simulate_insn()
> 
> v1:
>   -- Split the RFC patch #2 into two patches
>   -- Use larch_insn_gen_break() to generate break insns
>      for kprobes and uprobes
>   -- Pass around instruction word instead of union for
>      insns_not_supported(), insns_need_simulation() and
>      arch_simulate_insn() to avoid type conversion for callers
>   -- Add a simple test case for uprobes in the commit message
> 
> Tiezhu Yang (4):
>   LoongArch: Move three functions from kprobes.c to inst.c
>   LoongArch: Add larch_insn_gen_break() to generate break insns
>   LoongArch: Use larch_insn_gen_break() for kprobes
>   LoongArch: Add uprobes support
> 
>  arch/loongarch/Kconfig               |   3 +
>  arch/loongarch/include/asm/inst.h    |  16 ++++
>  arch/loongarch/include/asm/kprobes.h |   2 +-
>  arch/loongarch/include/asm/uprobes.h |  36 +++++++++
>  arch/loongarch/kernel/Makefile       |   1 +
>  arch/loongarch/kernel/inst.c         |  48 ++++++++++++
>  arch/loongarch/kernel/kprobes.c      |  75 ++++--------------
>  arch/loongarch/kernel/traps.c        |   9 +--
>  arch/loongarch/kernel/uprobes.c      | 142 +++++++++++++++++++++++++++++++++++
>  9 files changed, 265 insertions(+), 67 deletions(-)
>  create mode 100644 arch/loongarch/include/asm/uprobes.h
>  create mode 100644 arch/loongarch/kernel/uprobes.c
> 

I've test this series and found one corner case:

#include <pthread.h>
#include <stdio.h>
#include <thread>

static pthread_spinlock_t lock;
static int count = 0;
static const int n = 10000;

int main()
{
	int ret;

	ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
	if (ret)
		return -1;

	auto t1 = std::thread([&](){
		for (auto i = 0; i < n; i++) {
			pthread_spin_lock(&lock);
			count++;
			pthread_spin_unlock(&lock);
		}
	});

	auto t2 = std::thread([&](){
		for (auto i = 0; i < n; i++) {
			pthread_spin_lock(&lock);
			count++;
			pthread_spin_unlock(&lock);
		}
	});

	auto t3 = std::thread([&](){
		for (auto i = 0; i < n; i++) {
			pthread_spin_lock(&lock);
			count++;
			pthread_spin_unlock(&lock);
		}
	});

	t1.join();
	t2.join();
	t3.join();

	pthread_spin_destroy(&lock);

	printf("%d\n", count);
	return 0;
}

When I try to uprobe the pthread_spin_lock calls, the application core dumped.
On X86, this will return -EINVAL instead of crashing the userspace application.
Probably, we should add more opcode to insns_not_supported().

Cheers,
---
Hengqi

  parent reply	other threads:[~2023-04-17  3:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14  9:32 Tiezhu Yang
2023-04-14  9:32 ` [PATCH v2 1/4] LoongArch: Move three functions from kprobes.c to inst.c Tiezhu Yang
2023-04-14  9:32 ` [PATCH v2 2/4] LoongArch: Add larch_insn_gen_break() to generate break insns Tiezhu Yang
2023-04-14  9:33 ` [PATCH v2 3/4] LoongArch: Use larch_insn_gen_break() for kprobes Tiezhu Yang
2023-04-14  9:33 ` [PATCH v2 4/4] LoongArch: Add uprobes support Tiezhu Yang
2023-04-17  2:04   ` Youling Tang
2023-04-17  9:18     ` Tiezhu Yang
2023-04-17  3:17 ` Hengqi Chen [this message]
2023-04-17  9:22   ` [PATCH v2 0/4] Add uprobes support for LoongArch Tiezhu Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SY4P282MB351877A70A0333C790FE85A5C09C9@SY4P282MB3518.AUSP282.PROD.OUTLOOK.COM \
    --to=chenhengqi@outlook.com \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=loongson-kernel@lists.loongnix.cn \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®